3

How select the first Row default in UI-Grid in Angular JS:

I tried below code, but it is not working:

 $scope.gridOptions.data =  someData;
    $timeout(function () {
        $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
    },
    100) 

and Tried even below solution also but this is also not working :

 $scope.gridOptions.data =  someData;
    $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);

Could any one please suggest how to get it. Thanks in advance

3
  • which version is your ui-grid? Commented Feb 1, 2016 at 10:49
  • plnkr.co/edit/ycF3r1zu44hFTyn7rmG6?p=preview Commented Feb 1, 2016 at 10:59
  • Hi @VinoDang, I am using 3.1.0 UI-Grid and angular js version is 1.5.0-rc.1 Commented Feb 1, 2016 at 14:16

1 Answer 1

1

the following code requires ui-grid v3.0.0-rc.22, you can call modifyRows as follows:

$scope.gridOptions.data =  someData;
$scope.gridApi.grid.modifyRows($scope.gridOptions.data);
$scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);

No $timeout needed.

you can visit this page:https://github.com/angular-ui/ui-grid/issues/2267 or Angular ngGrid select row on page load

if the above code doesn't work, you can try the following code:

$scope.gridOptions = { 
    ... 
    onRegisterApi : function (gridApi) { 
    $scope.gridApi = gridApi;   
    $scope.gridApi.grid.modifyRows($scope.gridOptions.data); 
    $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
     }
};
Sign up to request clarification or add additional context in comments.

3 Comments

I tried this solution but it is not working, could you suggest any other solution, Thanks for advance !
could u have a plunker? if you have one, it would be helpful to resolve it!
try it like this: $scope.gridOptions = { ... onRegisterApi : function (gridApi) { $scope.gridApi = gridApi; $scope.gridApi.grid.modifyRows($scope.gridOptions.data); $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]); } };

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.