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?
Add $timeout
to your Controller and do this:
$timeout(function() {
$scope.gridOptions.selectRow(2, true);
});
Example: http://plnkr.co/edit/hDv7b8?p=preview
A solution without timeout can be found here: https://github.com/angular-ui/ui-grid/issues/2267 and here: Pre-Select rows on load with angular-ui-grid
$scope.gridOptions = {
...
onRegisterApi : function (gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.grid.modifyRows($scope.gridOptions.data);
$scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
}
};
Apparently modifyRows requires v3.0.0-rc.22+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With