Domanda

When I sort or filter something using ng-table, its $index doesn't get updated. If I have 4 items sorted ASC with deleteRow($Index) in ng-click, so the $index would be 0 to 3. Now if I sort them DESC, then the first row still has $index = 3, eventhough it should be 0. So I try to delete the first row, it ends up deleting the last row since the $Index is still set to 3. The same thing happens when I try to delete a filtered row.

Here's a demo: http://plnkr.co/edit/WCeBGm49F1QnvfUrHWG6?p=preview

È stato utile?

Soluzione

If you're using ng-repeat with orderBy, try the approach from this post to delete item.

Might looks like this:

HTML:

....
<tr ng-repeat="user in users | orderBy:'name':true">
    <td data-title="'Name'">
         <span ng-bind="user.name"></span>
         <button ng-click="remove(user)"></td>
</tr>
...

In controller:

$scope.remove = function(user){
   $scope.users.splice($scope.users.indexOf(user), 1);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top