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 ...
随机推荐
- [Android] 开发第八天
View 类是所有 UI组件的基类,它包含的 XML 属性和方法是所有组件都可使用的. ViewGroup 继承了 View 类,主要当作容器类使用,它是一个抽象类,实际使用中会使用它的子类作为容器. ...
- Android Studio 使用socks代理
Android Studio 使用socks代理 准备工作 1. 从https://www.privoxy.org/下载Privoxy软件 2. 安装Privoxy 3. 在Privoxy安装目录找到 ...
- 使用pandas时遇到ValueError: numpy.dtype has the wrong size, try recompiling
[问题]使用pandas时遇到ValueError: numpy.dtype has the wrong size, try recompiling [原因] 这是因为 Python 包的版本问题,例 ...
- Servlet讲解
第1章 Servlet的生命周期 1.1.1 Servlet的生命周期概述 1.1.1.1 什么是生命周期 生命周期:一个对象从创建到销毁过程. 1.1.1.2 Servlet的生命周期(*****) ...
- urllib2 Handler处理器和自定义opener(六)
Handler处理器 和 自定义Opener opener是 urllib2.OpenerDirector 的实例,我们之前一直都在使用的urlopen,它是一个特殊的opener(也就是模块帮我们构 ...
- oracle账户密码更新
oracle忘记用户名密码怎样恢复 首先cmd - sqlplusw 普通用户登陆:用户名:scott(普通用户名) 密码:tiger(普通用户密码) 管理员登陆:用户名:system 密码 ...
- OpenCL 图像卷积 2
▶ 上一篇图像卷积 http://www.cnblogs.com/cuancuancuanhao/p/8535569.html.这篇使用了 OpenCV 从文件读取彩色的 jpeg 图像,进行边缘检测 ...
- C# 二元一次方程参数求解
本文记录了关于求直线斜率及纵截距值的简单方法,只是简单的记录下求解思路,最终还需根据具体项目进行优化. 设直线方程式为:y=kx+b 编程思想: 1.代入y1与x1的值,得到:y1=kx1+b 2.代 ...
- leetcode532
public class Solution { public int FindPairs(int[] nums, int k) { var pair = new Dictionary<strin ...
- MySQL GTID (二)
MySQL GTID 系列之二 三.在线将GTID转化为传统模式 环境见上篇系列文章 关闭GTID,不用停止服务,不影响线上业务 3.1 关闭GTID复制,调整为传统复制 #SLVAE实例上停止复制 ...