deselect all rows in ng grid
Asked Answered
S

4

6

Please find the ng grid example in plunker

http://plnkr.co/edit/CncDWCktXTuBQdDVfuVv?p=preview

It will allow user to select only one row but there will be one selected row at all time. I want to deselect all rows.

Skeen answered 8/1, 2014 at 11:37 Comment(3)
when you want to deselect?Bahner
@Bahner I have two tabs each containing a grid. The second grid is populated according to the selected value of first grid. If nothing is selected the second grid will populate all records.Skeen
If one row is selected from first grid. There should be an option to deselect that row.Skeen
B
9

ng-grid has keepLastSelected option.

Try:

keepLastSelected: false in gridOptions. This will toggle selection.

Example

$scope.gridOptions = { 
      data: 'myData',
      selectedItems: $scope.mySelections,
      multiSelect: false,
      keepLastSelected: false
    };
Bahner answered 8/1, 2014 at 12:23 Comment(0)
O
5

The following works for me:

Plunker

First you need store gridApi:

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

Then you can use:

$scope.unSelectAll = function(){
    $scope.gridApi.selection.clearSelectedRows();
}
Overissue answered 9/2, 2015 at 20:14 Comment(0)
C
0

simply :

$scope.gridApi.selection.clearSelectedRows()
Cluj answered 3/10, 2017 at 16:33 Comment(0)
P
0

For Selecting ALL Rows We Use ::

$scope.GridOptions.api.selectAll()

Here $scope.GridOptions is your own grid data

And For Deselecting All Rows We use::

$scope.gridOptions.api.deselectAll();

Here (.api) is file and you get this file from (ag-grid.js) file from internet Url:https://cdnjs.com/libraries/ag-grid

Pillow answered 14/11, 2017 at 9:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.