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 to get the selected rows, but for me it always returns [] to keep track of the selected rows, I have to call gridApi.selection.getSelectedRows()

every time the select event fires, is that correct?

What I want to achieve is to make my own footer that keeps track of the number of selected grid rows, is this the correct way to achieve this?

+4


source to share


4 answers


There is already an example showing the number of selected items in the footer.

This plnkr shows the footer of the selected items. http://plnkr.co/edit/jc1YPCXBmfOKWyu8sLkx?p=preview



If you want to continue parsing the selected row, you can register a listener for the selected row and act on it.

 $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);
      });

      gridApi.selection.on.rowSelectionChangedBatch($scope,function(rows){
        var msg = 'rows changed ' + rows.length;
        $log.log(msg);
      });
    };

      

+5


source


I have a job without using an event trigger. I added a function, bound it to a button, and can only fetch selected items 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);
};
      

Run codeHide result


+4


source


This feature works for me when selectAll feature is activated. I got all the selected rows.

gridApi.selection.on.rowSelectionChangedBatch($scope,function(rows){
                    console.log(row);
                  });

      

0


source


$scope.gridOptions = {
  data: 'data',
  enableRowSelection: true,
  onRegisterApi: function(gridApi) { //register grid data first within the gridOptions
    $scope.gridApi = gridApi;
  }
};

      

Once you have access to the {{vm.gridApi.selection.getSelectedRows () variable. Length}} in the html template.

0


source







All Articles