Question: I am using function like : `gridApi.selection.clearSelectedRows();`

But how can I deselect the row in the following function event :

```
gridApi.selection.on.rowSelectionChanged($scope,function(row){};

```

The situation: I am open a popup and when I close the modalService I should unselect the last row I clicked.

Thanks

Answer: 
**Store last selected row object** 

```
$scope.lastSelectedRow = {};
 $scope.gridOptions.onRegisterApi = function (gridApi) {
                $scope.gridApi = gridApi;
                gridApi.selection.on.rowSelectionChanged($scope,function(row){
                if(row.isSelected) { 
                 // always store pointer to last row only if it is selected
                 $scope.lastSelectedRow = row;
                   } 
                });
            }

```

**Now you can unselect that row when you close the modal Instance** 

```
$scope.clearLastSelectedRow  = function() {
       $scope.gridApi.selection.unSelectRow($scope.lastSelectedRow.entity);
};

```

More details [here](http://ui-grid.info/docs/#/api/ui.grid.selection.api:PublicApi)
did you forget to store the gridApi? should look like below:

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

```

see this related [post](https://stackoverflow.com/questions/24959659/how-to-deselect-a-row-in-angular-js-programatically-in-ng-grid)