I am trying to provide a pagination to a table:
Let's say there are 100 records and records per page is 10. If I am in 3rd page, records from 21 to 30 should be prepared in the table.
So I am trying to filter those records using angular filter but couldn't succeed.
I tried multiple ways:
<tr on-last-repeat ng-repeat="record in data | filter:( $index>= fromRow && $index <= toRow)" role="row">- Created a custom filter but unable to pass either
$indexor record to thefilter. If record could be passed to the filter, so that I can get the index byrecords.indexOf(record).
Trying to pass $index:
<tr on-last-repeat ng-repeat="record in data | paging:$index:fromRow:toRow track by $index" role="row">
I found a solution in StackOverflow which is named as native filter:
<tr on-last-repeat ng-repeat="record in data | filter:filterPaging()" role="row">
$scope.filterPaging = function(){
return function(record){
var idx = $scope.data.indexOf(record)+1;
if(idx >= $scope.fromRow && idx <= $scope.toRow) return true;
return false;
}
};
But this function is getting called so many times. My table has 4 columns and 10 records and the function is being called for 40 times. I am concerning about performance if there are thousands of records.
Can somebody please take few minutes to have a look on this.
limitTofilter? Btw. on our projects we always ended up filtering arrays on-demand in the controller so that the ngRepeat does not use any filters.$indexor loopeditemto filter. Can you keep the comment as answer so that I can mark it as 'Accepted'.$indexor item) is created. So no, you can not use those in thengRepeatexpression.