Reputation: 1382
I just started using angularJS. I'm trying to implement item list using ng-repeat with pagination. Everything works fine except when I filter results. The problem is when there are more results then in fits in the page I don't know how much items in total I get so I can't regenerate pagination data.
To get filtered list count I use this:
$scope.filterApplied = function (filteredList, query) {
$scope.filteredItems = $filter('filter')(filteredList, query);
if ($scope.filteredItems != null) {
$scope.totalItems = filteredList.length;
}
};
but if I set max items per page to lets say 5 and there are 10 results $scope.totalItems
is equal to 5.
I need to somehow get the count of items after applying filter:query
but before limitTo:(itemsPerPage*currentPage)
and $index >= (currentPage -1)*5
.
How do I achieve this?
My ng-repeat part looks like this:
<tr ng-repeat="person in peopleList | filter:query | orderBy:orderByField:reverseSort | limitTo:(itemsPerPage*currentPage)" ng-if="lastResult($index)">
Upvotes: 0
Views: 140
Reputation: 21
You could be able to create a variable for limitTo in the controller and only set it after you get length of filtered list:
HTML
<tr ng-repeat="person in peopleList | filter:query | orderBy:orderByField:reverseSort | limitTo:limit" ng-if="lastResult($index)">
Controller
$scope.limit = ($scope.itemsPerPage*$scope.currentPage);
$scope.filterApplied = function (filteredList, query) {
$scope.filteredItems = $filter('filter')(filteredList, query);
if ($scope.filteredItems != null) {
$scope.limit=0;
$scope.totalItems = filteredList.length;
$scope.limit = ($scope.itemsPerPage*$scope.currentPage);
}
};
Upvotes: 2