Angularjs - 分页出现在搜索过滤器之后 [英] Angularjs - Pagination appear after search filter
本文介绍了Angularjs - 分页出现在搜索过滤器之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 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>
如果我错了,请纠正我.
Correct me, if I am wrong.
推荐答案
因为 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 next按钮修改为
In addition, I would modify the ng-disable next button to
button "ng-disabled="(currentPage + 1) == numberOfPages()"
我会添加到 search_notes onchange currentPage=1.
And I would add to search_notes onchange currentPage=1.
给你小提琴http://jsfiddle.net/rLots5zd/
这篇关于Angularjs - 分页出现在搜索过滤器之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文