How to get the cell value from ng-grid

江枫思渺然 提交于 2019-11-30 21:09:25

Acutally, I want to get a cell value and modify when user selects the cell at the table.

Above answers are using fixed columns's filed.. like

 $scope.selectedIDs.push( item.id ) // id is column filed

Instead of these answers, I found another way exactly what I want to achieve with.

Example code: http://plnkr.co/edit/wfiMhlJ7by4eUHojjKT4?p=preview

editableCellTemplate which is an option for columnDefs is used for solving this problem.

Angular is Aswome!!

Use the afterSelectionChange callback to extract the ids from the selection to an other array.

$scope.gridOptions = { 
    data: 'myData',
    selectedItems: $scope.mySelections,
    multiSelect: true,
    afterSelectionChange: function () {
      $scope.selectedIDs = [];
      angular.forEach($scope.mySelections, function ( item ) {
        $scope.selectedIDs.push( item.id )
      });
    }
  };

now you can reference {{selectedIDs}} from the template and has all the selected ids in it. Or just the first: {{selectedIDs[0]}}

See the working example here: http://plnkr.co/edit/xVwVWX

You can access the rowItem of the selected row with the arguments to the afterSelectionChange event. The entity property will have the id and name properties.

 $scope.gridOptions = { 
    data: 'myData',
    selectedItems: $scope.mySelections,
    multiSelect: true,
    afterSelectionChange: function (theRow, evt) {      
       alert(theRow.entity.id);
}

};

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!