Getting select rows from ng-grid?

社会主义新天地 提交于 2019-11-29 01:43:13

Based on the doc, selectedItems should be a property of $scope.gridOptions, so try this:

Controller

$scope.gridOptions = { data: 'myData', selectedItems: [] };

HTML

<pre>{{gridOptions.selectedItems}}</pre>

You can get selected items of ng-grid 2.x from:

$scope.gridOptions.$gridScope.selectedItems

In version 3 you can do:

$scope.gridOptions.onRegisterApi = function(gridApi){

  $scope.gridApi = gridApi;
  $scope.mySelectedRows=$scope.gridApi.selection.getSelectedRows();
}

Refer to http://ui-grid.info/docs/#/api/ui.grid.selection.api:PublicApi for more info.

For 3.0, you can capture rows as they're selected like this:

$scope.gridOptions.onRegisterApi = function(gridApi){
  //set gridApi on scope
  $scope.gridApi = gridApi;
  gridApi.selection.on.rowSelectionChanged($scope,function(row){
    var msg = 'row selected ' + row.isSelected;
    $log.log(msg);
  });
};

More info here: http://ui-grid.info/docs/#/tutorial/210_selection

I'm attempting to read a list of selected rows at the moment. The option appears to have moved, I can now find this in:

$scope.gridOptions.ngGrid.config.selectedItems

It appears to be read-only

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