Angularjs 分页控件
实现效果:

实现步骤:
1.分页页面:page.html,页面多余样式,需要自己去除。
<div class="row" ng-show="conf.totalItems > 0">
<div class="col-md-5 col-sm-12">
<div class="dataTables_info" id="sample_1_info" role="status" aria-live="polite" ng-show="true">
<!--Showing to of entries-->
<!--total {{ conf.numberOfPages }} page,total {{ conf.totalItems }}-->
the<input type="text" class="form-control input-xsmall input-inline" ng-model="jumpPageNum"
ng-keyup="jumpToPage($event)"/>page,
per page<select ng-model="conf.itemsPerPage" ng-options="option for option in conf.perPageOptions "
ng-change="changeItemsPerPage()" class="form-control input-xsmall input-inline"></select>
/total<strong>{{ conf.totalItems }}</strong>item <!--A total of {{ conf.numberOfPages }} pages article {{ conf.totalItems }}-->
</div>
</div>
<div class="col-md-7 col-sm-12">
<div class="dataTables_paginate paging_bootstrap_full_number" id="sample_1_paginate">
<ul class="pagination" style="visibility: visible;">
<li ng-click="firstPage()" ng-class="{disabled:isFirst()}"><a href="javascript:" title="first"><i
class="fa fa-angle-double-left"></i></a>
</li>
<li ng-click="prevPage()" ng-class="{disabled:isFirst()}"><a href="javascript:" title="prev"><i
class="fa fa-angle-left"></i></a></li>
<li ng-repeat="item in pageList track by $index" ng-click="changeCurrentPage(item)"
ng-class="{active: item == conf.currentPage, separate: item == '...'}"><a href="javascript:">{{ item
}}</a>
</li>
<li ng-click="nextPage()" ng-class="{disabled:isEnd()}"><a href="javascript:" title="next"><i
class="fa fa-angle-right"></i></a></li>
<li ng-click="lastPage()" ng-class="{disabled:isEnd()}"><a href="javascript:"
title="{{ getText('last') }}"><i
class="fa fa-angle-double-right"></i></a></li>
</ul>
</div>
</div>
</div>
2.分页控件:
angular.module('bet.paging', [])
.constant('pageSizeArray', [, , , , ])
.constant('pagingConstant', {
CURRENTPAGE: ,
ITEMSPERPAGE:
})
.directive('paging', paging);
function paging(pageSizeArray) {
return {
restrice: 'EA',
templateUrl: '/utils/page.html',
replace: true,
scope: {
conf: '='
},
link: function (scope, element, attrs) {
scope.changeCurrentPage = function (item) {
if (item == '...') {
return;
} else {
scope.conf.currentPage = item;
}
};
scope.conf.pagesLength = parseInt(scope.conf.pagesLength) ? parseInt(scope.conf.pagesLength) : ;
if (scope.conf.pagesLength % === ) {
scope.conf.pagesLength = scope.conf.pagesLength - ;
}
// conf.erPageOptions
if (!scope.conf.perPageOptions) {
scope.conf.perPageOptions = pageSizeArray;
}
// pageList
function getPagination() {
// conf.currentPage
scope.conf.currentPage = parseInt(scope.conf.currentPage) ? parseInt(scope.conf.currentPage) : ;
// conf.totalItems
scope.conf.totalItems = parseInt(scope.conf.totalItems);
// conf.itemsPerPage (default:15)
if (scope.conf.rememberPerPage) {
if (!parseInt(localStorage[scope.conf.rememberPerPage])) {
localStorage[scope.conf.rememberPerPage] = parseInt(scope.conf.itemsPerPage) ? parseInt(scope.conf.itemsPerPage) : ;
}
scope.conf.itemsPerPage = parseInt(localStorage[scope.conf.rememberPerPage]);
} else {
scope.conf.itemsPerPage = parseInt(scope.conf.itemsPerPage) ? parseInt(scope.conf.itemsPerPage) : ;
}
// numberOfPages
scope.conf.numberOfPages = Math.ceil(scope.conf.totalItems / scope.conf.itemsPerPage);
// judge currentPage > scope.numberOfPages
if (scope.conf.currentPage < ) {
scope.conf.currentPage = ;
}
if (scope.conf.currentPage > scope.conf.numberOfPages) {
scope.conf.currentPage = scope.conf.numberOfPages;
}
// jumpPageNum
scope.jumpPageNum = scope.conf.currentPage;
var perPageOptionsLength = scope.conf.perPageOptions.length;
// define state
var perPageOptionsStatus;
for (var i = ; i < perPageOptionsLength; i++) {
if (scope.conf.perPageOptions[i] == scope.conf.itemsPerPage) {
perPageOptionsStatus = true;
}
}
if (!perPageOptionsStatus) {
scope.conf.perPageOptions.push(scope.conf.itemsPerPage);
}
scope.conf.perPageOptions.sort(function (a, b) {
return a - b
});
scope.pageList = [];
if (scope.conf.numberOfPages <= scope.conf.pagesLength) {
for (i = ; i <= scope.conf.numberOfPages; i++) {
scope.pageList.push(i);
}
} else {
var offset = (scope.conf.pagesLength - ) / ;
if (scope.conf.currentPage <= offset) {
for (i = ; i <= offset + ; i++) {
scope.pageList.push(i);
}
scope.pageList.push('...');
scope.pageList.push(scope.conf.numberOfPages);
} else if (scope.conf.currentPage > scope.conf.numberOfPages - offset) {
scope.pageList.push();
scope.pageList.push('...');
for (i = offset + ; i >= ; i--) {
scope.pageList.push(scope.conf.numberOfPages - i);
}
scope.pageList.push(scope.conf.numberOfPages);
} else {
scope.pageList.push();
scope.pageList.push('...');
for (i = Math.ceil(offset / ); i >= ; i--) {
scope.pageList.push(scope.conf.currentPage - i);
}
scope.pageList.push(scope.conf.currentPage);
for (i = ; i <= offset / ; i++) {
scope.pageList.push(scope.conf.currentPage + i);
}
scope.pageList.push('...');
scope.pageList.push(scope.conf.numberOfPages);
}
}
if (scope.conf.onChange) {
scope.conf.onChange();
}
scope.$parent.conf = scope.conf;
}
// firstPage
scope.firstPage = function () {
scope.conf.currentPage = ;
};
// prevPage
scope.prevPage = function () {
if (scope.conf.currentPage > ) {
scope.conf.currentPage -= ;
}
};
// nextPage
scope.nextPage = function () {
if (scope.conf.currentPage < scope.conf.numberOfPages) {
scope.conf.currentPage += ;
}
};
//lastPage
scope.lastPage = function () {
scope.conf.currentPage = scope.conf.numberOfPages;
};
//is first page
scope.isFirst = function () {
if (scope.conf.currentPage > ) {
return false;
}
return true;
};
//is end page
scope.isEnd = function () {
if (scope.conf.currentPage < scope.conf.numberOfPages) {
return false;
}
return true;
};
// 跳转页
scope.jumpToPage = function () {
scope.jumpPageNum = scope.jumpPageNum.replace(/[^-]/g, '');
if (scope.jumpPageNum !== '') {
scope.conf.currentPage = scope.jumpPageNum;
}
};
scope.changeItemsPerPage = function () {
if (scope.conf.rememberPerPage) {
localStorage.removeItem(scope.conf.rememberPerPage);
}
};
scope.$watch(function () {
var newValue = scope.conf.currentPage + ' ' + scope.conf.totalItems + ' ';
if (scope.conf.rememberPerPage) {
if (localStorage[scope.conf.rememberPerPage]) {
newValue += localStorage[scope.conf.rememberPerPage];
} else {
newValue += scope.conf.itemsPerPage;
}
} else {
newValue += scope.conf.itemsPerPage;
}
return newValue;
}, getPagination);
//scope.getText = function (key) {
// return currentPage.text[key];
//};
}
}
};
3.页面调用:
<paging conf="pagingConf"></paging>
//声明user模块并引入bet.paging子模块
angular.module('bet.user', ['bet.paging']); angular
.module('bet.user')
.controller('userAppCtrl', userAppCtrl); //依赖注入pagingConstant
userAppCtrl.$inject = ['$scope', 'pagingConstant']; function userAppCtrl($scope, pagingConstant) {
//paging config
$scope.pagingConf = {
currentPage: pagingConstant.CURRENTPAGE,
itemsPerPage: pagingConstant.ITEMSPERPAGE,
totalItems:
}; });
Angularjs 分页控件的更多相关文章
- 自定义angularjs分页控件
继昨天写了knockoutjs+ jquery pagination+asp.net web Api 实现无刷新列表页 ,正好最近刚学习angularjs ,故琢磨着写一个angularjs版本的分页 ...
- 在DevExpress程序中使用Winform分页控件直接录入数据并保存
一般情况下,我们都倾向于使用一个组织比较好的独立界面来录入或者展示相关的数据,这样处理比较规范,也方便显示比较复杂的数据.不过在一些情况下,我们也可能需要直接在GridView表格上直接录入或者修改数 ...
- asp.net webform 自定义分页控件
做web开发一直用到分页控件,自己也动手实现了个,使用用户自定义控件. 翻页后数据加载使用委托,将具体实现放在在使用分页控件的页面进行注册. 有图有真相,给个直观的认识: 自定义分页控件前台代码: & ...
- asp.net分页控件
一.说明 AspNetPager.dll这个分页控件主要用于asp.net webform网站,现将整理代码如下 二.代码 1.首先在测试页面Default.aspx页面添加引用 <%@ Reg ...
- 仿淘宝分页按钮效果简单美观易使用的JS分页控件
分页按钮思想: 1.少于9页,全部显示 2.大于9页,1.2页显示,中间页码当前页为中心,前后各留两个页码 附件中有完整例子的压缩包下载.已更新到最新版本 先看效果图: 01输入框焦点效果 ...
- winform快速开发平台 -> 基础组件之分页控件
一个项目控件主要由及部分的常用组件,当然本次介绍的是通用分页控件. 处理思想:我们在处理分页过程中主要是针对数据库操作. 一般情况主要是传递一些开始位置,当前页数,和数据总页数以及相关关联的业务逻辑. ...
- 基于存储过程的MVC开源分页控件--LYB.NET.SPPager
摘要 现在基于ASP.NET MVC的分页控件我想大家都不陌生了,百度一下一大箩筐.其中有不少精品,陕北吴旗娃杨涛大哥做的分页控件MVCPager(http://www.webdiyer.com/)算 ...
- AspNetPager分页控件配置
AspNetPager是asp.net中常用的分页控件,下载AspNetPager.dll,添加引用,在工具栏就可以看到AspNetPager控件: 拖过来之后,设置如下属性: <webdiye ...
- 分页控件layui的使用
$.getJSON( )的使用方法简介 $.getJSON( url [, data ] [, success(data, textStatus, jqXHR) ] ) url是必选参数,表示json ...
随机推荐
- HDU-6156 Palindrome Function(数位DP)
一.题目 二.思路 1.这是很明显的数位DP: 2.和以往数位DP不同的是,这里带了个进制进来,而以往做是纯十进制下或者纯二进制下做操作.但是,不管多少进制,原理都是一样的: 3.这里有个小坑,题目中 ...
- 图搜索——使用DFS和BFS耗时比较
图测试数据生成代码: #include<bits/stdc++.h> using namespace std; int random(int mod) { return rand() % ...
- javascript使用bind指定接收者
var json = { jArray: [], jPush: function (c) { this.jArray.push(c); } } var examp = ["123" ...
- Windows 程序 dump 崩溃调试
Windows 程序捕获崩溃异常 生成dump 概述 事情的起因是,有个同事开发的程序,交付的版本程序,会偶尔随机崩溃了. 悲催的是没有输出log,也没有输出dump文件. 我建议他给程序代码加个异常 ...
- 检测Python程序的执行效率
无意中被问到代码执行效率的问题,那就总结一下检测代码执行效率的几种方式: 一.装饰器 在函数上加装饰器,来得到函数的执行时间. def cst_time(func, *args, **kwargs): ...
- Backing up the tail
The tail of the transaction log usually refers to the contents of the database's transaction log tha ...
- 10 MySQL--权限管理
权限管理 1.创建账号 # 本地账号 create user '; # mysql -uegon1 -p123 # 远程帐号 create user '; # mysql -uegon2 -p123 ...
- OpenCV学习笔记 - Video Analysis - 录制视频
录制视频 使用自带摄像头录制一段5s的短视频 error & solution fourcc1 = cv2.CV_FOURCC(', 'v') 在实践过程中,运行这一行时报错: 原因分析 在o ...
- BashProfile
[BashProfile] ~/.bash_profile. alias ll='ls -l -G -a' alias gp='grep --colour -R'
- mybatis使用foreach进行批量插入和删除操作
一.批量插入 1.mapper层 int insertBatchRoleUser(@Param("lists") List<RoleUser> lists);//@Pa ...