arnavakhoury
arnavakhoury

Reputation: 125

Set focus to newly added row in ui-grid

I am using ui-grid. The use-case is such that on clicking a button, a new row is added. I want to set focus on the first cell of the newly added row Any suggestions on how to do it ? Here's a plunkr for the same. http://plnkr.co/edit/6zyZ5q

$scope.addNew = function() {
var newobj = {"id": "","name":"" }; 
$scope.gridOptions.data.unshift(newobj);
$scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ROW); 

//set focus to the new row 
$scope.gridApi.cellNav.scrollToFocus( $scope.gridOptions.data[0], $scope.gridOptions.columnDefs[0]);
};

Upvotes: 4

Views: 3556

Answers (1)

Christian Nagel
Christian Nagel

Reputation: 201

$timeout(function() {
  $scope.gridApi.cellNav.scrollToFocus(
    $scope.termGridOptions.data[0],
    $scope.termGridOptions.columnDefs[0]
 );
});

I hope it helps.

Upvotes: 2

Related Questions