Ng-grid source row index

I am customizing a cell template in an ng grid. In this cell, I want to have a button that will trigger some kind of event that needs a row index in the original data array. The template is as follows:

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

and removeItemis executed as follows:

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

This works until I sort the grid by clicking one of the columns. Apparently rowIndex is a visual row pointer, not the row index in the array I provided.

Is there a way to get the actual index?

+4
source share
2 answers

, , - , . , . -

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

, .

+5

ngGrid -

indexOf(row.entity)

HTML

<input type="button" value="remove" ng-click="removeRow(row)" />

Javascript

$scope.removeRow = function(row) {
    var index = $scope.myData.indexOf(row.entity);
    $scope.myData.splice(index, 1);
};

Plunker

+4

All Articles