How to add row to ng grid and then select this row?

My team tried to do the following:

$scope.addTest = function () { var TestRow = { "name": "xx", "description": "xx", "subjectId": 15 }; $scope.gridOptions.selectAll() var testRowLength = $scope.gridData.push(TestRow); $scope.gridOptions.selectItem(testRowLength - 1, true); } 

However, the last selectItem does the wrong selection. Therefore, we tried the following:

  $scope.$apply(function () { $scope.gridData.push(TestRow); $scope.gridOptions.selectItem(testRowLength - 1, true); }); 

Now we get the error message:

 Error: $apply already in progress 

This issue has been posted as an issue on the ng-grid blog, but it has just been published and we need help with this as soon as possible. I hope someone can give us advice on how we can

+4
source share
1 answer

You select the row too quickly, use ngGridEventData . I push new lines to the top of the grid, so scrolling is a little easier:

 $scope.add = function(){ var emptyContact = Utilities.newContact(); var e = $scope.$on('ngGridEventData', function() { $scope.contactsGridOptions.selectItem(0, true); window.scrollTo(0,0); e(); }); $scope.contacts.unshift(emptyContact); }; 

Scrolling Details: How to scroll ngGrid to show current selection?

A related issue with ng-grid: https://github.com/angular-ui/ng-grid/issues/354

+7
source

All Articles