admin管理员组

文章数量:1305023

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
}

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
}
Share Improve this question asked Jul 25, 2014 at 15:49 SaiBandSaiBand 5,37517 gold badges58 silver badges79 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 3

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

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...

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

both of them work for me.

Instead of

this.selectedItems = []

do

this.selectedItems.length =0

This works for me!!

for one item:

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

Just use

$scope.gridOptions.selectAll(false);

This works for me.

本文标签: javascriptHow to deselect a row in angular js programatically in ng gridStack Overflow