SaiBand
SaiBand

Reputation: 5355

How to deselect a row in angular js programatically in ng grid

I have an ng-grid and it allows multiple selections.

After doing a save operation, I want to deselect the selected rows.

I tried doing something like this.selectedItems = [].

However, when I do that, if I select a row in ng-grid later, it doesnt bind to this.selectedItems. Instead it just remains an empty array.

My question here is on save, I want to be able deselect selected row.After that, any rows I select should bind to this.selectedItems.

Following is what I have for Grid options.

Any ideas and suggestions are greatly appreciated.

this.$scope.gridOptions = {
      data: 'myData',
      enablePaging: true,
      showFooter: true,
      totalServerItems: 'totalServerItems',
      pagingOptions: this.$scope.pagingOptions,
      sortInfo: this.$scope.sortOptions,
      useExternalSorting: true,
      selectedItems: this.selectedItems,
      multiSelect: true
}

Upvotes: 4

Views: 7975

Answers (6)

Nico
Nico

Reputation: 888

The following is working 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();
}

Upvotes: 3

Habib Adıbelli
Habib Adıbelli

Reputation: 1181

This works for me!!

for one item:

 var index = row.rowIndex; //selected row index
  vm.expenseDataGridOptions.selectItem( index , false)

Upvotes: 0

Ryan Pang
Ryan Pang

Reputation: 1

Just use

$scope.gridOptions.selectAll(false);

This works for me.

Upvotes: -1

Souji
Souji

Reputation: 86

  1. $scope.gridOptions.$gridScope.toggleSelectAll(false, false); // note: false,false
  2. this.selectedItems.length =0

both of them work for me.

Upvotes: 1

lbrazier
lbrazier

Reputation: 2654

Instead of

this.selectedItems = []

do

this.selectedItems.length =0

Upvotes: 0

harishr
harishr

Reputation: 18055

i actually had faced the same issue and after looking at the code of ng-grid, i had arrived at below solution

$scope.gridOptions.$gridScope.toggleSelectAll(false, true);

i dont remember the details of the parameters now, sorry for that...

Upvotes: 1

Related Questions