0

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.

3 Answers 3

2

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;
    });
}; 
Sign up to request clarification or add additional context in comments.

Comments

1

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)\"" +
    ....
);

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.