Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ui-grid 3.0 get selected rows

This answer states that this code:

$scope.gridOptions.onRegisterApi = function(gridApi){
  $scope.gridApi = gridApi;
  $scope.mySelectedRows=$scope.gridApi.selection.getSelectedRows();
}

Should work in order to get the selected rows, but to me it returns always [], to get track of selected rows I have to call gridApi.selection.getSelectedRows() each time a selection event is triggered, is this correct ?

What I want to achieve is to do my own footer that tracks the number of selected rows of the grid, is this the correct way of achieving this ?

like image 742
kitensei Avatar asked Dec 20 '22 03:12

kitensei


1 Answers

I have it working w/o having to use the event trigger. I added a function, tied it to a button and can retrieve selected items only when I need them.

$scope.gridOptions = {
  data: 'data',
  enableRowSelection: true,
  onRegisterApi: function(gridApi) { //register grid data first within the gridOptions
    $scope.gridApi = gridApi;
  }
};
//this is the on click function
$scope.getCurrentSelection = function() {
  var currentSelection = $scope.gridApi.selection.getSelectedRows();
  console.log(currentSelection);
};
like image 50
Roman K Avatar answered Dec 24 '22 01:12

Roman K