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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With