How to programmatically select a row in Ui.grid angularJs?

HkFreaKuser1673718 picture HkFreaKuser1673718 · Jun 29, 2015 · Viewed 26.7k times · Source

I have an issue let me put it simple in my plunker example I want to know why is my $scope.revertSelection() function not working. http://plnkr.co/edit/3KXrUuCsSACuhefmyzxN?p=info

Steps:

  1. Sort right hand grid by Name(descending order)

  2. Select 3-4 rows randomly

  3. Click 'Copy' button all selected rows are copied into $scope.retainSelection

  4. Sort right hand grid by Name(Ascending order)

  5. Click 'Revert' button (this is not working)

I am expecting all the rows previously selected in step 2) to be selected back which is not happening :-( please help me with the issue. I googled but could not find any docs of gridApi.selection to look for other methods to fulfill my requirement.

Note: I am using Ui.grid not ng-grid

Answer

HkFreaKuser1673718 picture HkFreaKuser1673718 · Jun 29, 2015

I should use...

$scope.gridApi.grid.modifyRows($scope.gridOptions.data);
$scope.gridApi.selection.selectRow($scope.gridOptions.data[i]);

...instead of...

$scope.gridApi.selection.selectRow(i);

My friend gave link to docs.