Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-grid original row index

I am customizing a cell template in ng-grid. In that cell, I want to have a button that will trigger some event that needs the row index into the original data array. The template looks like this:

<button class="btn" ng-click="removeItem(row.rowIndex)">
  <i class="icon-remove"></i>
</button>

and removeItem is implemented like this:

$scope.removeItem = function(rowIndex) { $scope.myList.splice(rowIndex, 1) }

This works until I re-sort the grid by clicking on one of the columns. Apparently, rowIndex the visual index of the row, and not the index of the row in the array I supplied.

Is there a way to obtain the actual index?

like image 656
thesamet Avatar asked Jan 12 '23 06:01

thesamet


1 Answers

One easy way that i can think of would be to add a property index on the model data itself and initialize it when you get the data. This way you always have the initial row order. Something like

angular.forEach(items,function(item,index){
   item.index=index;
});

I don't think the grid provides any such mechanism.

like image 152
Chandermani Avatar answered Jan 22 '23 05:01

Chandermani