angularUI bootstrap提供的分页插件满足了大部分应用的需求,具体内容如下
在项目需求中,新增了两个需求:
1.自由设定每页显示的条目;
rush:xhtml;">
IoUs-text="‹" next-text="›" first-text="«" last-text="»">
disabled="inputCurPage==''||submitting">Go
css代码
rush: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代码
rush:js;">
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; //当前页数
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
};
}]);