2

我有一个要求,在 ag-grid 中,我需要打开一个菜单来添加/编辑/删除该行数据。我正在使用角度材质菜单组件作为单元格模板 url。但是当单击该菜单项时,它不会触发 ag-grid 中的 onCellClicked 事件以获取对单击的行数据的引用,但是如果我单击远离菜单项的像素,则会触发事件。需要帮助弄清楚,如何在菜单单击时获取行数据。

我的 ag-grid 代码在这里:

var columnDefs = [
    {headerName: "", field: "icon", width:65},
    {headerName: "Categories",field:"category_name", width:1025, cellRenderer:function(params){
    // my cell renderer code goes here
      },
   onCellClicked:function(params){
      console.log("Cell is still getting click "+params.data);
  //This click does not work
    },

    {headerName: "", field: "options", width:87, suppressMenu: true, templateUrl:"partials/options.html"
  }
];

选项.html

<md-menu>
  <!-- <md-button aria-label="Open phone interactions menu" class="md-icon-button" ng-click="openMenu($mdOpenMenu, $event)">
    <md-icon md-svg-src="images/icons/options.svg" aria-label="android "></md-icon>
  </md-button> -->
  <a href="javascript:void(0)" class="option-btn" ng-click="openMenu($mdOpenMenu, $event)">options</a>
  <md-menu-content width="4">
    <md-menu-item>
      <md-button ng-click="modifyOptions($event)">
        <md-icon md-svg-src="images/icons/add.svg" aria-label="android "></md-icon>
        Add
      </md-button>
    </md-menu-item>
    <md-menu-item>
      <md-button ng-click="toggleNotifications()">
        <md-icon md-svg-src="images/icons/edit.svg" aria-label="android "></md-icon>
        Edit
      </md-button>
    </md-menu-item>
    <md-menu-divider></md-menu-divider>
    <md-menu-item>
      <md-button disabled="disabled" ng-click="checkVoicemail()">
        <md-icon md-svg-src="images/icons/delete.svg" aria-label="android "></md-icon>
        Delete
      </md-button>
    </md-menu-item>
  </md-menu-content>

4

1 回答 1

0

我找到了我的问题的答案,虽然这并不难:单元格模板引用了每一行的数据对象,因此可以通过调用来访问属性data.your_property。在这里,我根本不需要 onCellClicked 事件。以下是工作代码:

var columnDefs = [
    {headerName: "", field: "icon", width:65},
    {headerName: "Categories",field:"category_name", width:1025, cellRenderer:function(params){

      // Cell Renderer goes here
},

    {headerName: "", field: "options", width:87, suppressMenu: true, templateUrl:"partials/options.html"
  }
];

选项.html

<md-menu>

  <a href="javascript:void(0)" class="option-btn" ng-    click="openMenu($mdOpenMenu, $event, **data**)">options</a>
<md-menu-content width="4">
<md-menu-item>
  <md-button ng-click="modifyOptions($event, data)">
    <md-icon md-svg-src="images/icons/add.svg" aria-label="android "></md-icon>
    Add
  </md-button>
</md-menu-item>
<md-menu-item>
  <md-button ng-click="modifyCategory(data)">
    <md-icon md-svg-src="images/icons/edit.svg" aria-label="android "></md-icon>
    Edit
  </md-button>
</md-menu-item>
<md-menu-divider></md-menu-divider>
<md-menu-item>
  <md-button disabled="disabled" ng-click="deleteCategory(data)">
    <md-icon md-svg-src="images/icons/delete.svg" aria-label="android "></md-icon>
    Delete
  </md-button>
</md-menu-item>

于 2016-03-04T04:54:38.823 回答