AngularJs分頁插件使用詳解
angularUI bootstrap提供的分頁插件滿足了大部分應(yīng)用的需求,具體內(nèi)容如下
在項(xiàng)目需求中,新增了兩個(gè)需求:
1.自由設(shè)定每頁顯示的條目;
2.可以手動(dòng)輸入頁面,跳轉(zhuǎn)到指定的頁數(shù)。
html代碼
<div class="pagination-define p20 mt20" ng-hide="totalItems==0">
<select ng-model="perPageSize" ng-change="pageChanged({currentPage:currentPage,perPageSize:perPageSize})" >
<option value=10 ng-selected="perPageSize==10">10</option>
<option value=20>20</option>
<option value=30>30</option>
<option value=50>50</option>
<option value=100>100</option>
</select>
<uib-pagination items-per-page="numPerPage" total-items="totalItems" ng-model="currentPage" ng-change="pageChanged({currentPage:currentPage,perPageSize:perPageSize})" max-size="5" class="pagination-sm" boundary-link-numbers="true" boundary-links="true" rotate="false" previous-text="‹" next-text="›" first-text="«" last-text="»"></uib-pagination>
<input type="text" ng-model="inputCurPage" min=1 cus-max-number ="{{maxPages}}" current-page="{{currentPage}}">
<button class="btn btn-info btn-30h" ng-click="pageChanged({currentPage:inputCurPage,perPageSize:perPageSize})" ng-disabled="inputCurPage==''||submitting">Go</button>
</div>
css代碼
.pagination-define{
text-align: center
}
.pagination-define input, .pagination-define select {
padding-left: 3px;
height: 30px;
vertical-align: top;
border: 1px solid #ccc;
border-radius: 4px;
width: 50px;
}
.pagination {
margin: 0;
}
.pagination-define .btn-30h {
vertical-align: top;
}
.btn-30h {
padding-top: 4px;
padding-bottom: 4px;
}
Javascript代碼
app.directive('cusMaxNumber', ['$timeout', function ($timeout) {
return {
restrict: 'EA',
require: 'ngModel',
scope: {
maxNumber: '@cusMaxNumber',
currentPage: '@currentPage'
},
link: function (scope, element, attr, ctrl) {
ctrl.$parsers.push(function (viewValue) {
var maxNumber = parseInt(scope.maxNumber, 10);
var curNumber = scope.currentPage; //當(dāng)前頁數(shù)
var transformedInput = viewValue.replace(/[^0-9]/g, '');
if (transformedInput !== viewValue||parseInt(transformedInput,10)<1||parseInt(transformedInput,10)>maxNumber) {
ctrl.$setViewValue(curNumber);
ctrl.$render();
return curNumber;
}
return viewValue;
});
}
};
}])
.directive('cusPagination',[function(){
return {
restrict: "E",
templateUrl: 'views/template/pagination.html',
scope: {
numPerPage: "=numPerPage",
totalItems: "=totalItems",
currentPage: "=cusCurrentPage",
perPageSize:"=perPageSize",
inputCurPage:"=inputCurPage",
maxPages:"=maxPages",
pageChanged: "&pageChanged"
},
replace: false
};
}]);
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- angularjs表格分頁功能詳解
- angularjs實(shí)現(xiàn)的前端分頁控件示例
- ANGULARJS中使用JQUERY分頁控件
- AngularJS實(shí)現(xiàn)分頁顯示數(shù)據(jù)庫信息
- 基于Angularjs實(shí)現(xiàn)分頁功能
- Angularjs分頁查詢的實(shí)現(xiàn)
- 學(xué)習(xí)Angularjs分頁指令
- AngularJS 與Bootstrap實(shí)現(xiàn)表格分頁實(shí)例代碼
- 詳解angularjs結(jié)合pagination插件實(shí)現(xiàn)分頁功能
- Angularjs 實(shí)現(xiàn)分頁功能及示例代碼
相關(guān)文章
詳解Angular調(diào)試技巧之報(bào)錯(cuò)404(not found)
本篇文章主要介紹了詳解Angular調(diào)試技巧之報(bào)錯(cuò)404(not found),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01
Angular中實(shí)現(xiàn)樹形結(jié)構(gòu)視圖實(shí)例代碼
近兩年當(dāng)中使用Angular開發(fā)過很多項(xiàng)目,其中也涉及到一些樹形結(jié)構(gòu)視圖的顯示,最近的在項(xiàng)目中封裝了大量的組件,一些組件也有樹形結(jié)構(gòu)的展示,所以寫出來總結(jié)一下。2017-05-05
AngularJS實(shí)現(xiàn)Model緩存的方式
這篇文章主要介紹了AngularJS實(shí)現(xiàn)Model緩存的方式,分享了多種AngularJS實(shí)現(xiàn)Model緩存的方法,感興趣的小伙伴們可以參考一下2016-02-02
angularJs select綁定的model取不到值的解決方法
今天小編就為大家分享一篇angularJs select綁定的model取不到值的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-10-10
詳解基于angular-cli配置代理解決跨域請(qǐng)求問題
本篇文章主要介紹了詳解基于angular-cli配置代理解決跨域請(qǐng)求問題,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07

