实现效果:

  

实现步骤:

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 分页控件的更多相关文章

  1. 自定义angularjs分页控件

    继昨天写了knockoutjs+ jquery pagination+asp.net web Api 实现无刷新列表页 ,正好最近刚学习angularjs ,故琢磨着写一个angularjs版本的分页 ...

  2. 在DevExpress程序中使用Winform分页控件直接录入数据并保存

    一般情况下,我们都倾向于使用一个组织比较好的独立界面来录入或者展示相关的数据,这样处理比较规范,也方便显示比较复杂的数据.不过在一些情况下,我们也可能需要直接在GridView表格上直接录入或者修改数 ...

  3. asp.net webform 自定义分页控件

    做web开发一直用到分页控件,自己也动手实现了个,使用用户自定义控件. 翻页后数据加载使用委托,将具体实现放在在使用分页控件的页面进行注册. 有图有真相,给个直观的认识: 自定义分页控件前台代码: & ...

  4. asp.net分页控件

    一.说明 AspNetPager.dll这个分页控件主要用于asp.net webform网站,现将整理代码如下 二.代码 1.首先在测试页面Default.aspx页面添加引用 <%@ Reg ...

  5. 仿淘宝分页按钮效果简单美观易使用的JS分页控件

    分页按钮思想:  1.少于9页,全部显示  2.大于9页,1.2页显示,中间页码当前页为中心,前后各留两个页码  附件中有完整例子的压缩包下载.已更新到最新版本  先看效果图:  01输入框焦点效果  ...

  6. winform快速开发平台 -> 基础组件之分页控件

    一个项目控件主要由及部分的常用组件,当然本次介绍的是通用分页控件. 处理思想:我们在处理分页过程中主要是针对数据库操作. 一般情况主要是传递一些开始位置,当前页数,和数据总页数以及相关关联的业务逻辑. ...

  7. 基于存储过程的MVC开源分页控件--LYB.NET.SPPager

    摘要 现在基于ASP.NET MVC的分页控件我想大家都不陌生了,百度一下一大箩筐.其中有不少精品,陕北吴旗娃杨涛大哥做的分页控件MVCPager(http://www.webdiyer.com/)算 ...

  8. AspNetPager分页控件配置

    AspNetPager是asp.net中常用的分页控件,下载AspNetPager.dll,添加引用,在工具栏就可以看到AspNetPager控件: 拖过来之后,设置如下属性: <webdiye ...

  9. 分页控件layui的使用

    $.getJSON( )的使用方法简介 $.getJSON( url [, data ] [, success(data, textStatus, jqXHR) ] ) url是必选参数,表示json ...

随机推荐

  1. mysql-8 alter命令

    当我们需要修改数据表名或者修改数据表字段时,就需要用到Mysql alter命令. 查看表结构: -- 以下2个命令是通用的 show columns from test_alter_tbl; des ...

  2. mysql-1安装和数据库的管理

    1.安装 直接docker安装,客户端使用Navicat Premium. docker run -d --name csjmysql -p 3306:3306 -e MYSQL_ROOT_PASSW ...

  3. 详解jenkins几个有用的插件如何使用(emma,findbugs)

    原文:http://myeyeofjava.iteye.com/blog/1765552 findbugs使用方式: 目的:进行代码走查的自动化,能够提示垃圾代码或者提供代码优化的建议 1.首先下载f ...

  4. Eureka 客户端 配置Eureka 爬坑

    配置客户端 eureka.client.register-with-eureka=true eureka.client.fetch-registry=true eureka.client.servic ...

  5. SC命令安装window服务

    sc create Styler binpath= "D:\Styler\Styler.exe" start= auto displayname= "Styler&quo ...

  6. Mybatis之XML使用Enum枚举传递数据

    在Mybatis中,处理枚举类的TypeHandler有两个: EnumTypeHandler: 用于保存枚举名 EnumOrdinalTypeHandler: 用于保存枚举的序号. 在实际项目中,以 ...

  7. Frequently Used Shell Commands

    [Common Use Shell Commands] 1.ps aux:查看当前所有进程 ,以用户名为主键.可以查看到 USER.PID.COMMAND(binary所有位置) 2.netstat ...

  8. 滑动窗口的中位数 · Sliding Window Median

    [抄题]: 给定一个包含 n 个整数的数组,和一个大小为 k 的滑动窗口,从左到右在数组中滑动这个窗口,找到数组中每个窗口内的中位数.(如果数组个数是偶数,则在该窗口排序数字后,返回第 N/2 个数字 ...

  9. python在windows环境安装MySQLdb

    一.环境 系统:win7,64位 python版本:2.7.15 pip版本:10.0.1 二.安装 1. 用pip安装 pip install MySQLdb 报错: Could not find ...

  10. Redis开发、管理实战

    一.数据类型 String : 字符类型 Hash: 字典类型 List: 列表 Set: 集合 Sorted set: 有序集合 二.全局Key操作 KEYS * 查看KEY支持通配符 DEL 删除 ...