Search code examples
javascriptangularjsangular-ui-grid

How to get correct rowEntity in Angular UI grid?


I'm currently working on the Angular UI grid. The edit functionality is implemented and it works fine except one case when I push or remove any row to/from a grid at first after that I receive an incorrect rowEntity object during row editing. I believe it is easy to get a reason of "issue" who has valuable experience.

Let's say a grid contains two rows initially. Then I add a row to the top with: $scope.gridOptions.data.unshift(//here is an object);

Thus, there are already 3 rows in the grid. If I try to edit the third row, I'll get an rowEntity object with data from the current second row instead of the third.

onRegisterApi: function(gridApi) {
  $scope.gridApi = gridApi;

  $scope.gridApi.rowEdit.on.saveRow($scope, function (rowEntity) {
    //the rowEntity object is incorrect here if any row was either added or removed before the row that is under edit action now
  }
}

What am I doing wrong? What do I misunderstand or don't know? I could resolve it if it would be possible to pass a rendered index row in on.saveRow().


Solution

  • Reloaded DOM of the grid to get correct sequence of rowEntities.