Angular ngGrid select row on page load

Sanath picture Sanath · Aug 29, 2013 · Viewed 14.2k times · Source

My question is an extension to thisquestion

Getting select rows from ng-grid?

plunker - http://plnkr.co/edit/DiDitL?p=preview

I need a row to be selected on page load and I need to avoid listening to 'ngGridEventData'

calling $scope.gridOptions.selectRow(2, true); in the controller body fails since the grid has not been loaded.

avoiding listening to ngGridEventData is due to the fact that I need the controller to listen to an event triggered before and based on that I need to select the nggrid row.

any ideas?

Answer

user508994 picture user508994 · Oct 15, 2013

Add $timeout to your Controller and do this:

$timeout(function() { 
    $scope.gridOptions.selectRow(2, true); 
});

Example: http://plnkr.co/edit/hDv7b8?p=preview