分享一个asp.net pager分页控件


Posted in Javascript onJanuary 04, 2012

效果:

分享一个asp.net pager分页控件
js:

$.fn.extend({ JPager: function (cfg, pageIndex, pageSize) { 
if (cfg && pageIndex > 0 && pageSize>0) { 
var token = "#" + this.attr("id"); 
this.empty(); 
var pageFirst = function () { 
$(token).JPager(cfg, 1, pageSize); 
}; 
var pagePre = function () { 
$(token).JPager(cfg, pageIndex - 1, pageSize); 
}; 
var pageLast = function () { 
$(token).JPager(cfg, parseInt($("#_tot").val()), pageSize); 
}; 
var pageNext = function () { 
$(token).JPager(cfg, pageIndex + 1, pageSize); 
}; 
var pageNumber = function () { 
$(token).JPager(cfg, parseInt($(this).text()), pageSize); 
}; 
var pageGo = function () { 
var index = parseInt($("#_pos").val()); 
var total = parseInt($("#_tot").val()); 
if (index) { 
if (index > total) { 
$(token).JPager(cfg, total, pageSize); 
} 
else if (index < 1) { 
$(token).JPager(cfg, 1, pageSize); 
} 
else { 
$(token).JPager(cfg, index, pageSize); 
} 
} 
}; 
var checkGoNumber = function () { 
if (!Number(this.value)) { 
this.value = ""; 
} 
else { 
this.value = Number(this.value); 
} 
}; 
var initCustomer = function (recordCount) { 
if (cfg.customer) { 
if (cfg.customer.template) { 
var t = cfg.customer.template; 
t = t.replace(/\%total\%/gi, Math.ceil(recordCount / pageSize)).replace(/\%current\%/gi, pageIndex).replace(/\%recordCount\%/gi, recordCount).replace(/\%pageSize\%/gi, pageSize); 
if (cfg.customer.position == "right") { 
$("#_right").after(t); 
} 
else { 
$("#_left").before(t); 
} 
} 
} 
}; 
var changeState = function (total) { 
if (pageIndex == 1) { 
$("#_first").attr("class", "unable"); 
$("#_pre").attr("class", "unable"); 
} 
else { 
$("#_first").bind("click", pageFirst).attr("class", "number"); 
$("#_pre").bind("click", pagePre).attr("class", "number"); 
} 
if (pageIndex == total) { 
$("#_last").attr("class", "unable"); 
$("#_next").attr("class", "unable"); 
} 
else { 
$("#_last").bind("click", pageLast).attr("class", "number"); 
$("#_next").bind("click", pageNext).attr("class", "number"); 
} 
}; 
var initNumber = function (total, count, current) { 
if (total > 0 && count > 0) { 
if (current < 1) { 
current = 1; 
} 
if (current > total) { 
current = total; 
} 
var endIndex = total; 
var startIndex = 1; 
var temp = current + Math.floor(count / 2); 
if (temp < total) { 
if (temp < count) { 
endIndex = count; 
} 
else { 
startIndex = temp - count + 1; 
endIndex = temp; 
} 
} 
else { 
if (total > count) { 
startIndex = total - count + 1; 
} 
} 
$("#_number").empty(); 
for (var i = startIndex; i <= endIndex; i++) { 
var html = $("<span></span>").text(i).bind("click", pageNumber); 
if (i == current) { 
$("#_number").append(html.attr("class", "selected")); 
} 
else { 
$("#_number").append(html.attr("class", "number")); 
} 
} 
} 
}; 
var initPager = function (data) { 
if ($.isArray(data.SearchResult) && data.RecordCount > 0) { 
$(token).append("<span id='_left'><span id='_first' class='spcial'>首页</span> <span id='_pre' class='spcial'>上一页</span></span> <span id='_number'></span><span id='_go'><input id='_pos' type='text'/><input id='_to' type='button' value='GO'/></span> <span id='_right'><span id='_next' class='spcial'>下一页</span> <span id='_last' class='spcial'>末页</span></span><input id='_tot' type='hidden'/>"); 
var total = Math.ceil(data.RecordCount / pageSize); 
$("#_tot").val(total); 
$("#_pos").bind("blur", checkGoNumber); 
$("#_to").bind("click", pageGo); 
changeState(total); 
if (cfg.showNumber && cfg.count > 0) { 
initNumber(total, cfg.count, pageIndex); 
} 
initCustomer(data.RecordCount); 
} 
}; 
if (cfg.action) { 
if (cfg.action.url && cfg.action.data) { 
var d = cfg.action.data.substr(0, cfg.action.data.lastIndexOf("}")) + ',"pageIndex":' + pageIndex + ',"pageSize":' + pageSize + "}"; 
if (cfg.action.callback && $.isFunction(cfg.action.callback)) { 
$.ajax({ 
type: "post", 
url: cfg.action.url, 
dataType: "json", 
contentType: "text/json", 
data: d, 
success: function (data) { 
initPager(data.d); 
cfg.action.callback(data.d); 
} 
}); 
} 
else { 
$.ajax({ 
type: "post", 
url: cfg.action.url, 
dataType: "json", 
contentType: "text/json", 
data: d, 
success: function (data) { 
initPager(data.d); 
} 
}); 
} 
} 
} 
} 
} 
});

css:
#_pos { 
width: 40px; 
} 
.unable 
{ 
color: #BCC0BB; 
} 
.number 
{ 
margin: 2px; 
color:#0000FF; 
text-decoration:underline; 
} 
.selected 
{ 
margin: 2px; 
color: #FF0000; 
font-weight: bold; 
}

html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>分页控件示例</title> 
<link href="CSS/JPager.css" rel="stylesheet" type="text/css" /> 
<script src="JS/jquery.min.js" type="text/javascript"></script> 
<script src="JExtension/JPager.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(function () { 
$("#pager").JPager({ customer:{template:"%cuRRent%"},count: 10, action: { url: "Service/JService.svc/GetPersons", data: '{"name":"zhoulq"}'}, showNumber: true },1,5); 
}); 
</script> 
</head> 
<body> 
<table> 
</table> 
<div id="pager"></div> 
</body> 
</html>

wcf:
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.ServiceModel.Activation; 
using System.ServiceModel.Web; 
namespace JPlugin 
{ 
[ServiceContract] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class JService 
{ 
[OperationContract] 
[WebInvoke] 
public PageObject<Person> GetPersons(string name,int pageIndex,int paseSize) 
{ 
return new PageObject<Person>(){RecordCount = 23,SearchResult = new List<Person>(){new Person(){Name="zhpulq",Age = 28},new Person(){Name = "zhouxy",Age = 24}}}; 
} 
} 
public class PageObject<T> 
{ 
public int RecordCount { get; set; } 
public List<T> SearchResult { get; set; } 
} 
}
Javascript 相关文章推荐
jQuery 核心函数以及jQuery对象
Mar 23 Javascript
Javascript中的相等与不等运算
Apr 25 Javascript
js 实现菜单左右滚动显示示例介绍
Nov 21 Javascript
纯js写的分页表格数据为json串
Feb 18 Javascript
jQuery实现渐变下拉菜单的简单方法
Mar 11 Javascript
理解 JavaScript Scoping &amp; Hoisting(二)
Nov 18 Javascript
Spring MVC中Ajax实现二级联动的简单实例
Jul 06 Javascript
js 判断数据类型的几种方法
Jan 13 Javascript
微信小程序后台解密用户数据实例详解
Jun 28 Javascript
解决vue this.$forceUpdate() 处理页面刷新问题(v-for循环值刷新等)
Jul 26 Javascript
微信小程序学习笔记之跳转页面、传递参数获得数据操作图文详解
Mar 28 Javascript
js实现简单页面全屏
Sep 17 Javascript
调试Node.JS的辅助工具(NodeWatcher)
Jan 04 #Javascript
DOM和XMLHttpRequest对象的属性和方法整理
Jan 04 #Javascript
40个有创意的jQuery图片和内容滑动及弹出插件收藏集之三
Jan 03 #Javascript
40个有创意的jQuery图片和内容滑动及弹出插件收藏集之二
Dec 31 #Javascript
40个有创意的jQuery图片、内容滑动及弹出插件收藏集之一
Dec 31 #Javascript
js 遍历对象的属性的代码
Dec 29 #Javascript
js当一个变量为函数时 应该注意的一点细节小结
Dec 29 #Javascript
You might like
ip签名探针
2006/10/09 PHP
php多次include后导致全局变量global失效的解决方法
2015/02/28 PHP
php实现购物车产品删除功能(2)
2020/07/23 PHP
php中的explode()函数实例介绍
2019/01/18 PHP
一个收集图片的bookmarlet(js 刷新页面中的图片)
2010/05/27 Javascript
jquery下实现overlay遮罩层代码
2010/08/25 Javascript
为jquery的ajaxfileupload增加附加参数的方法
2014/03/04 Javascript
jquery实现鼠标滑过小图查看大图的方法
2015/07/20 Javascript
Javascript BOM学习小结(六)
2015/11/26 Javascript
基于jQuery实现带动画效果超炫酷的弹出对话框(附源码下载)
2016/02/22 Javascript
JavaScript中判断数据类型的方法总结
2016/05/24 Javascript
用原生js做单页应用
2017/01/17 Javascript
TableSort.js表格排序插件使用方法详解
2017/02/10 Javascript
微信小程序对接七牛云存储的方法
2017/07/30 Javascript
深入理解js A*寻路算法原理与具体实现过程
2018/12/13 Javascript
详解vue-cli项目在IE浏览器打开报错解决方法
2020/12/10 Vue.js
用Python输出一个杨辉三角的例子
2014/06/13 Python
Django教程笔记之中间件middleware详解
2018/08/01 Python
[原创]Python入门教程1. 基本运算【四则运算、变量、math模块等】
2018/10/28 Python
python 获取微信好友列表的方法(微信web)
2019/02/21 Python
Python学习笔记之Zip和Enumerate用法实例分析
2019/08/14 Python
Python3开发实例之非关系型图数据库Neo4j安装方法及Python3连接操作Neo4j方法实例
2020/03/18 Python
python与idea的集成的实现
2020/11/20 Python
CSS3 实现的缩略图悬停效果
2020/12/09 HTML / CSS
莫斯科大型旅游休闲商品超市:Camping.ru
2020/09/16 全球购物
留学自荐信
2013/10/10 职场文书
群众路线教育实践活动方案
2014/02/02 职场文书
离婚协议书范文2014(夫妻感情破裂)
2014/12/14 职场文书
颐和园导游词
2015/01/30 职场文书
门卫管理制度范本
2015/08/05 职场文书
网吧员工管理制度
2015/08/05 职场文书
缅怀先烈主题班会
2015/08/14 职场文书
详解Redis复制原理
2021/06/04 Redis
Windows11性能真的上涨35%? 桌面酷睿i9实测结果公开
2021/11/21 数码科技
Win11任务栏无法正常显示 资源管理器不停重启的解决方法
2022/07/07 数码科技
Promise静态四兄弟实现示例详解
2022/07/07 Javascript