前端源码:

<div>
<h1>列表页33</h1>
<table>
<thead>
<tr><td>CandiID</td><td>HotelName</td></tr>
</thead>
<tr ng-repeat="item in List track by $index"><td>{{item.CandiID}}</td><td>{{item.HotelName}}</td></tr>
</table>
<div>
<%--<pagination ></pagination>--%>
</div>

<div>
<tm-pagination conf="paginationConf"></tm-pagination>
</div>

</div>

AngularJS

var listModule = angular.module('app.farmhouselist', []);

//控制器
var listCtrl = function ($scope, $http, $q, GetCandidateListByCondition) {
var conditionObj = new Object();
conditionObj.Province = 23;
conditionObj.SourceType = 128;
conditionObj.SalesManName = 'xixi';
conditionObj.UserCategory = "0";
conditionObj.CurrentUser = "xixi";

var condition = JSON.stringify(conditionObj);

var GetAllEmployee = function () {

var postData = {
pageIndex: $scope.paginationConf.currentPage,
pageSize: $scope.paginationConf.itemsPerPage
};
//任务单
GetCandidateListByCondition.event(condition, postData.pageIndex, postData.pageSize).then(function (data) {
$scope.List = eval(data.PageData);
$scope.totalCount = data.TotalCount;

$scope.paginationConf.totalItems = data.TotalCount;
});
}
//配置分页基本参数
$scope.paginationConf = {
currentPage: 1,
itemsPerPage: 15
};

$scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage', GetAllEmployee);

}

listModule.controller("listCtrl", ['$scope', listCtrl]);

//分页指令
listModule.directive("tmPagination", function () {
return {
restrict: 'EA',
//template: '<div class="page-list">' +
// '<ul class="pagination" ng-show="conf.totalItems > 0">' +
// '<li ng-class="{disabled: conf.currentPage == 1}" ng-click="prevPage()"><span>&laquo;</span></li>' +
// '<li ng-repeat="item in pageList track by $index" ng-class="{active: item == conf.currentPage, separate: item == \'...\'}" ' +
// 'ng-click="changeCurrentPage(item)">' +
// '<span>{{ item }}</span>' +
// '</li>' +
// '<li ng-class="{disabled: conf.currentPage == conf.numberOfPages}" ng-click="nextPage()"><span>&raquo;</span></li>' +
// '</ul>' +
// '<div class="page-total" ng-show="conf.totalItems > 0">' +
// '第&nbsp;<input type="text" ng-model="jumpPageNum" ng-keyup="jumpToPage($event)"/>&nbsp;页 ' +
// '每页&nbsp;<select ng-model="conf.itemsPerPage" ng-options="option for option in conf.perPageOptions " ng-change="changeItemsPerPage()"></select>' +
// '&nbsp;共<strong>{{ conf.totalItems }}</strong>&nbsp;条' +
// '</div>' +
// '<div class="no-items" ng-show="conf.totalItems <= 0">暂无数据</div>' +
// '</div>',

template: '<div class="page-list">' +
'<ul class="pagination" ng-show="conf.totalItems > 0">' +
'<li ng-class="{disabled: conf.currentPage == 1}" ng-click="prevPage()"><span>&laquo;</span></li>' +
'<li ng-repeat="item in pageList track by $index" ng-class="{active: item == conf.currentPage, separate: item == \'...\'}" ' +
'ng-click="changeCurrentPage(item)">' +
'<span>{{ item }}</span>' +
'</li>' +
'<li ng-class="{disabled: conf.currentPage == conf.numberOfPages}" ng-click="nextPage()"><span>&raquo;</span></li>' +
'</ul>' +
'<div class="page-total" ng-show="conf.totalItems > 0">' +
'第&nbsp;<input type="text" ng-model="jumpPageNum" ng-keyup="jumpToPage($event)"/>&nbsp;页 ' +
'&nbsp;每页{{conf.itemsPerPage}}条' +
'&nbsp;共<strong>{{ conf.totalItems }}</strong>&nbsp;条' +
'</div>' +
'<div class="no-items" ng-show="conf.totalItems <= 0">暂无数据</div>' +
'</div>',
replace: true,
scope: {
conf: '='
},
link: function (scope, element, attrs) {

// 变更当前页
scope.changeCurrentPage = function (item) {
if (item == '...') {
return;
} else {
scope.conf.currentPage = item;
}
};

// 定义分页的长度必须为奇数 (default:9)
scope.conf.pagesLength = parseInt(scope.conf.pagesLength) ? parseInt(scope.conf.pagesLength) : 10;
if (scope.conf.pagesLength % 2 === 0) {
// 如果不是奇数的时候处理一下
scope.conf.pagesLength = scope.conf.pagesLength - 1;
}

// conf.erPageOptions
if (!scope.conf.perPageOptions) {
scope.conf.perPageOptions = [10, 15, 20, 30, 50];
}

// pageList数组
function getPagination() {
// conf.currentPage
scope.conf.currentPage = parseInt(scope.conf.currentPage) ? parseInt(scope.conf.currentPage) : 1;
//scope.conf.totalItems
//判断一下scope.conf.totalItems,如果是undefined,直接返回不执行后面的代码 add by cpf
if (scope.conf.totalItems==undefined) {
return;
}
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) : 15;
}

scope.conf.itemsPerPage = parseInt(localStorage[scope.conf.rememberPerPage]);

} else {
scope.conf.itemsPerPage = parseInt(scope.conf.itemsPerPage) ? parseInt(scope.conf.itemsPerPage) : 15;
}

// numberOfPages
scope.conf.numberOfPages = Math.ceil(scope.conf.totalItems / scope.conf.itemsPerPage);

// judge currentPage > scope.numberOfPages
if (scope.conf.currentPage < 1) {
scope.conf.currentPage = 1;
}

if (scope.conf.currentPage > scope.conf.numberOfPages) {
scope.conf.currentPage = scope.conf.numberOfPages;
}

// jumpPageNum
scope.jumpPageNum = scope.conf.currentPage;

// 如果itemsPerPage在不在perPageOptions数组中,就把itemsPerPage加入这个数组中
var perPageOptionsLength = scope.conf.perPageOptions.length;
// 定义状态
var perPageOptionsStatus;
for (var i = 0; i < perPageOptionsLength; i++) {
if (scope.conf.perPageOptions[i] == scope.conf.itemsPerPage) {
perPageOptionsStatus = true;
}
}
// 如果itemsPerPage在不在perPageOptions数组中,就把itemsPerPage加入这个数组中
if (!perPageOptionsStatus) {
scope.conf.perPageOptions.push(scope.conf.itemsPerPage);
}

// 对选项进行sort
scope.conf.perPageOptions.sort(function (a, b) { return a - b });

scope.pageList = [];
if (scope.conf.numberOfPages <= scope.conf.pagesLength) {
// 判断总页数如果小于等于分页的长度,若小于则直接显示
for (i = 1; i <= scope.conf.numberOfPages; i++) {
scope.pageList.push(i);
}
} else {
// 总页数大于分页长度(此时分为三种情况:1.左边没有...2.右边没有...3.左右都有...)
// 计算中心偏移量
var offset = (scope.conf.pagesLength - 1) / 2;
if (scope.conf.currentPage <= offset) {
// 左边没有...
for (i = 1; i <= offset + 1; 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(1);
scope.pageList.push('...');
for (i = offset + 1; i >= 1; i--) {
scope.pageList.push(scope.conf.numberOfPages - i);
}
scope.pageList.push(scope.conf.numberOfPages);
} else {
// 最后一种情况,两边都有...
scope.pageList.push(1);
scope.pageList.push('...');

for (i = Math.ceil(offset / 2) ; i >= 1; i--) {
scope.pageList.push(scope.conf.currentPage - i);
}
scope.pageList.push(scope.conf.currentPage);
for (i = 1; i <= offset / 2; 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;
}

// prevPage
scope.prevPage = function () {
if (scope.conf.currentPage > 1) {
scope.conf.currentPage -= 1;
}
};
// nextPage
scope.nextPage = function () {
if (scope.conf.currentPage < scope.conf.numberOfPages) {
scope.conf.currentPage += 1;
}
};

// 跳转页
scope.jumpToPage = function () {
scope.jumpPageNum = scope.jumpPageNum.replace(/[^0-9]/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 + ' ';
// 如果直接watch perPage变化的时候,因为记住功能的原因,所以一开始可能调用两次。
//所以用了如下方式处理
if (scope.conf.rememberPerPage) {
// 由于记住的时候需要特别处理一下,不然可能造成反复请求
// 之所以不监控localStorage[scope.conf.rememberPerPage]是因为在删除的时候会undefind
// 然后又一次请求
if (localStorage[scope.conf.rememberPerPage]) {
newValue += localStorage[scope.conf.rememberPerPage];
} else {
newValue += scope.conf.itemsPerPage;
}
} else {
newValue += scope.conf.itemsPerPage;
}
return newValue;

}, getPagination);

}
};
});

AngularJS 分页的更多相关文章

  1. 自定义angularjs分页控件

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

  2. angularjs 分页精华代码

    //pageinfo $scope.pageSize=10;$scope.currentType={{ current_type }};$scope.currentPage={{ json_encod ...

  3. AngularJS分页实现

    基本思路 一开始页码为1,Service向服务器端获取对应信息:点击上/下一页/跳转,通过对应的页码向服务器端获取对应的信息. 由于后台暂时没弄好,我实现的过程中直接读取准备好的JSON文件,通过页码 ...

  4. Angularjs 分页控件

    实现效果: 实现步骤: 1.分页页面:page.html,页面多余样式,需要自己去除. <div class="row" ng-show="conf.totalIt ...

  5. angularjs分页组件

    这是我第一次写博客,激动,首先,我也是个菜鸟,分享一下自己写的服务器端分页的代码,自己一步一步写的,其中也有参考别人的代码.技术比较渣,先这样了. // ====== 2019-1-3 ======/ ...

  6. 前端使用AngularJS的$resource,后端ASP.NET Web API,实现分页、过滤

    在上一篇中实现了增删改查,本篇实现分页和过滤. 本系列包括: 1.前端使用AngularJS的$resource,后端ASP.NET Web API,实现增删改查2.前端使用AngularJS的$re ...

  7. Angularjs 跳转页面并传递参数的方法总结

    http://www.zhihu.com/question/33565135 http://www.codeproject.com/Articles/1073780/ASP-NET-MVC-CRUD- ...

  8. angular.js分页代码的实例

    对于大多数web应用来说显示项目列表是一种很常见的任务.通常情况下,我们的数据会比较多,无法很好地显示在单个页面中.在这种情况下,我们需要把数据以页的方式来展示,同时带有转到上一页和下一页的功能.现在 ...

  9. 有了jsRender,妈妈再也不用担心我用jq拼接DOM拼接的一团糟了、页面整齐了、其他伙伴读代码也不那么费劲了

    写在前面 说来也很巧, 下午再做一个页面,再普通不过的分页列表,我还是像往常一样,基于MVC环境下,我正常用PagedList.MVC AJAX做无刷新分页,这时候问题就来了,列表数据中有个轮播图用到 ...

随机推荐

  1. Qt——透明无边框Widget的bug

    Experience 最近在封装一些类的时候,打算做一个窗口框架,能实现拖动.缩放.最大最小化.基本样式等功能,可不慎遇见一件无比蛋疼的事情,QWidget最小化后再恢复正常界面,最小化按钮居然仍处于 ...

  2. 直接启动tomcat时为tomcat指定JDK

    第一种: 在windows环境下以批处理文件方式启动tomcat,只要运行<CATALINA_HOME>/bin/startup.bat这个文件,就可以启动Tomcat.在启动时,star ...

  3. knockoutJS学习笔记06:ko数组与模板绑定

    前面已经介绍了基本的绑定和模板相关知识,接下来就看ko里的数组和模板绑定,数组和模板绑定应该是实际项目中用得比较多的,ko提供了很好的支持. 一.observaleArray 前面的监控属性都是单个对 ...

  4. Django 1.9 Post 时候出现 CSRF token missing or incorrect 错误

    get 的时候没有问题,只有在post的时候出现出现这个错误 在方法中加入 @csrf_exempt

  5. redis 学习 01(下载 学习资源)

    1. windows 版 redis 下载地址 https://github.com/MSOpenTech/redis/releases 2. redis 实战源码 http://redisinact ...

  6. 【UOJ #244】【UER #7】短路

    http://uoj.ac/contest/35/problem/244 对其他人来说好简单的一道题,我当时却不会做TWT 注定滚粗啊 题解很好的~ #include<cstdio> #i ...

  7. [转]win 10 开始菜单(Win 7风格)增强工具 StartIsBack++ v1.3.4 简体中文特别版

    Windows10开始菜单增强工具StartIsBack++现已更新至v1.3.4,最近主要修复在Win10周年更新版上恢复睡眠后任务栏通知中心按钮消失的问题.升级版对StartIsBack+全新构建 ...

  8. jQuery datatables

    jQuery datatables 属性,用例 参考:http://datatables.club/example/ http://blog.csdn.net/mickey_miki/article/ ...

  9. [C#] 使用NPOI将Datatable保存到Excel

    using (table) { IWorkbook workbook = new HSSFWorkbook(); ISheet sheet = workbook.CreateSheet(); IRow ...

  10. Google Maps API V3 之 图层

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...