1

I have my ng-repeat and filter ,then I added bootstrap-ui pagination and everything working fine

To add fields Edit, I needed to use 'track by $index' but I cant find the correct way to add it to my ng-repeat, This is my HTML view :

<tr data-ng-repeat="target in targets | filter:search | startFrom:(currentPage - 1) * pageSize  | limitTo: pageSize "> 
  <td><input type="text" ng-model-options="{ updateOn: 'blur' }" ng-change="updateTarget(targets[$index])" ng-model="targets[$index].YEAR"></td>
  <td><input type="text" ng-model-options="{ updateOn: 'blur' }" ng-change="updateTarget(targets[$index])" ng-model="targets[$index].MONTH"></td>
  <td><input type="text" ng-model-options="{ updateOn: 'blur' }" ng-change="updateTarget(targets[$index])" ng-model="targets[$index].TV"></td>
</tr>

Here is my table screen shot

My PageSize Limit is set to 5, so my index restart from 1 to 5 in every page cause I didn't added track by $index in my ng-repeat So if I edit row number 2, it will edit every row number 2 in every page,

Any idea for how to add 'track by $index' when using Filter and Pagination in the same ng-repeat

Inoubli
  • 374
  • 2
  • 11

1 Answers1

0

According to the Angular documentation here:

Note: track by must always be the last expression:

<div ng-repeat="model in collection | orderBy: 'id' as filtered_result track by model.id">
    {{model.name}}
</div>
Rob J
  • 6,609
  • 5
  • 28
  • 29
  • I'm pretty sure `model in collection track by $index | orderBy: 'id'` works too... – Muli Yulzary May 12 '16 at 12:58
  • I tested my ng-repeat without pagination like this : and I get my index working, the problem is when I add "| startFrom:(currentPage - 1) * pageSize | limitTo: pageSize track by $index" I cant get my table any more, To resume Filter + Track by $index works, Filter + Pagination works too, but Filter + pagination + track by $index not working – Inoubli May 12 '16 at 14:16