实现效果:

  

实现步骤:

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. Some index files failed to download. They have …… or old ones used instead

    问题: 平台:Ubuntu12.04 W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/precise/universe/bin ...

  2. 由python的math.log想到的问题

    result = math.log(243,3) print(result) 输出5.0 print("%f"%result) 还是输出5.0 看出问题了吗?对,没错.int(5. ...

  3. JVM 调优参数设置

    先看Linux内存大小(假设为2G) cat /proc/meminfo |grep MemTotal 查看java初始配置 java -XX:+PrintFlagsInitial Tomcat配置 ...

  4. Maven(九)”编码 gbk 的不可映射字符“ 问题解决方案

    解决这个问题的思路: 在maven的编译插件中声明正确的字符集编码编码——编译使用的字符集编码与代码文件使用的字符集编码一致!! 安装系统之后,一般中文系统默认字符集是GBK.我们安装的软件一般都继承 ...

  5. log.error(msg)和log.error(msg,e)的显示区别

    log.error(msg): [2017-10-18 11:31:07,652] [Thread-7] (CmsCtlDataUploadFileExchange.java:50) ERROR co ...

  6. javascript数组操作(创建、元素删除、数组的拷贝)

    这篇文章主要介绍了javascript数组操作,包括创建.元素的访问.元素删除.数组的拷贝等操作,还有其它示例,需要的朋友可以参考下 1.数组的创建 复制代码 代码如下: var arrayObj = ...

  7. EmEditor的正则表达式

    前提是 "使用正则表达式"的复选框打上勾. 1 查找<>之间的字符串:   ".*?"2 查找双引号之间的字符串:   ".*?" ...

  8. 46. Permutations (Back-Track,Sort)

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  9. 117. Populating Next Right Pointers in Each Node II (Tree; WFS)

    Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...

  10. input实时监听控制输入框的输入内容和长度,并进行提示和反馈

    一.前言 在MVVM模式下,有个双向数据绑定(data-binding)的优势,可以通过viewmodel实时的监听用户操作,也可以将model的改动实时的反馈到界面上. 那么,在传统的js操控DOM ...