Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
166
rated 0 times [  169] [ 3]  / answers: 1 / hits: 45774  / 11 Years ago, mon, april 22, 2013, 12:00:00

I already have the pagination implemented.
Now I want the pagination to be updated after filtering my results.



The form:



<input type=text data-ng-model=search.name data-ng-change=filter()/>


The list:



<li data-ng-repeat=data in filtered = (list | filter:search) | filter:search | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit>{{data.name}}</li>


The pagination:



<pagination data-boundary-links=true data-num-pages=noOfPages data-current-page=currentPage max-size=maxSize></pagination>


The controller:



$scope.filter = function() {
window.setTimeout(function() { //wait for 'filtered' to be changed
$scope.noOfPages = Math.ceil($scope.filtered.length/$scope.entryLimit);
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
}, 10);
};


My problem is, the pagination is just updated after clicking on a page number or after entering the next character into the input field. So it is update one step to late.



EDIT: I added the source to jsFiddle: http://jsfiddle.net/eqCWL/2/


More From » angularjs

 Answers
8

Use $timeout instead of window.setTimeOut. $timeout is wrapped properly to work consistently in Angular.


[#78732] Saturday, April 20, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isaacvalentinn

Total Points: 325
Total Questions: 120
Total Answers: 131

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
isaacvalentinn questions
Mon, Jan 18, 21, 00:00, 3 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Wed, Sep 23, 20, 00:00, 4 Years ago
;