Coder
Coder

Reputation: 223

Show selected row count in pagination in ui-grid

I am using ui-grid in my project, I need to show the selected row index value in pagination part.

For example, there are total 100 items in my grid, it is divided into 4 pages, each page has 25 items. If I select 10th row from a page, I need show 10 of 25 items

I am using :

HTML

 <div ui-grid="gridOptions" ui-grid-selection > </div>

controller:

  $scope.gridOptions ={

  data:'data',
  coulmnDef: $scope.coulmnDef,
  paginationPageSizes: [25, 50, 75,100],
  paginationPageSize: 25,

};

could you please help me any one, Thanks in advance

Upvotes: 1

Views: 2612

Answers (1)

iH8
iH8

Reputation: 28638

You can get the selected rows by listening for rowSelectionChanged event, after which you can use the getSelectedRows method on gridApi's selection object. To do so, add the following to your gridOptions object:

$scope.selection = [];

$scope.gridOptions = {
    enableRowSelection: true,
    enableRowHeaderSelection: false,
    modifierKeysToMultiSelect: true,
    multiSelect: true,
    onRegisterApi: function (gridApi) {
        $scope.gridApi = gridApi;
        gridApi.selection.on.rowSelectionChanged($scope, function () {
            $scope.selection = gridApi.selection.getSelectedRows();
        });
    }
};

Now everytime the selection changes, the selection array in your scope gets updated of which you can take the length property which gives you the selection count. Hope that helps, good luck!

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

Upvotes: 1

Related Questions