Udayanga Ranasinghe
Udayanga Ranasinghe

Reputation: 1

How to get selected row in angularjs UI-GRID on row selected event

I have an ui-grid in my application and I want to get the selected row when user select a row from the grid (single row selectable grid).

I know how to get the selected rows through gridApi when click on a button. But I'm unable to get a selected row immediately at the row selected event.

Upvotes: 0

Views: 4166

Answers (3)

Nikhil Kumar K
Nikhil Kumar K

Reputation: 1117

Need to register api function and use as shown below

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

   $scope.gridApi = gridApi;

   gridApi.selection.on.rowSelectionChanged($scope, function(row){ 
    $scope.countRows = $scope.gridApi.selection.getSelectedRows().length;
    });

   gridApi.selection.on.rowSelectionChangedBatch($scope, function(row){ 
    $scope.countRows = $scope.gridApi.selection.getSelectedRows().length;
    });
}; 

Upvotes: 2

Manu
Manu

Reputation: 10934

JUST ADD :

gridApi.selection.on.rowSelectionChanged($scope,function(row){
    console.log(row.entity);
  });

in registor api function of ui grid. row.entity will give the selected row

more details here : http://ui-grid.info/docs/#/tutorial/210_selection

Upvotes: 0

CMR
CMR

Reputation: 933

You could bind ng-click on the row, that gets the $event.

Modify the template and reference the appScope

$templateCache.put('ui-grid/uiGridViewport',
    ....
    "<div ng-repeat=\"(rowRenderIndex, row) in rowContainer.renderedRows track by $index\"" +
    "ng-click=\"grid.appScope.onClickRow(row, $event)\"" +
    ....
);

Upvotes: 1

Related Questions