Angular.js-分页出现在搜索过滤器之后 [英] Angularjs - Pagination appear after search filter
本文介绍了Angular.js-分页出现在搜索过滤器之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是AngularJS的新手.
I am newbie on AngularJS.
搜索结果可以显示在一页中,但是为什么 下一个和上一个按钮显示?
Search result can be displayed in one page but why the next and previous button is showing ?
http://jsfiddle.net/2ZzZB/1473/
<input type="text" id="txtNotessearch" ng-model="search_notes" class="form-control input-sm" placeholder="SEARCH">
...
<ul>
<li ng-repeat="item in data | filter:search_notes | startFrom:currentPage*pageSize | limitTo:pageSize">
{{item}}
</li>
</ul>
纠正我,如果我错了.
推荐答案
因为未过滤NumberOfPages. 除了使用$ scope.data.length之外,还应使用过滤器后面的长度.
Because NumberOfPages is not filtered. Instead of using $scope.data.length, you should use the length after the filter.
function MyCtrl($scope, $filter) { //Do not forget to inject $filter
$scope.currentPage = 0;
$scope.pageSize = 10;
$scope.data = [];
$scope.numberOfPages=function(){
var myFilteredData = $filter('filter')($scope.data,$scope.search_notes); //Filter the data
return Math.ceil(myFilteredData.length/$scope.pageSize);
}
for (var i=0; i<45; i++) {
$scope.data.push("Item "+i);
}
}
此外,我将ng-disable下一个按钮修改为
In addition, I would modify the ng-disable next button to
button "ng-disabled="(currentPage + 1) == numberOfPages()"
然后我将onchange currentPage = 1添加到search_notes中.
And I would add to search_notes onchange currentPage=1.
这里有小提琴 http://jsfiddle.net/rLots5zd/
这篇关于Angular.js-分页出现在搜索过滤器之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文