1:数据库表创建并往中插入200000条数据:

复制代码

CREATE TABLE [dbo].[T_School](

[ID] [int] IDENTITY(1,1) NOT NULL,

[SchoolName] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL,

[BuildDate] [datetime] NULL,

[Address] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,

[IsSenior] [bit] NULL,

[StudentNum] [int] NULL,

CONSTRAINT [PK_T_School] PRIMARY KEY CLUSTERED

(

[ID] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

复制代码

2:myJqgrid.js封装后的JqGird代码:

复制代码

/*

* 返回json格式中 最好默认带有ID列

默认显示 20列

* 列表id = "gridTable"

列表url = 'Handler.ashx?action=page'

列表datatype = 'json'

列表colNames = ['ID', "名称", '性别', '手机', '邮箱']

列表colModel = 。。。

列表标题 caption = "用户列表"

列表修改URL editurl = "Handler.ashx?action=oper"

列表默认排序 sortname = "ID";

页码ID gridPagerID = "gridPager"

*/

//最后选中的行

var lastsel;

function myJqGrid(id, url, datatype, colNames, colModel, caption, editurl, sortname, gridPagerID) {

var myGrid = $("#" + id);

myGrid.jqGrid({

url: url,

datastr: "data.json",

datatype: datatype,

rowNum: 20,

rowList: [10, 20, 50],

colNames: colNames,

colModel: colModel,

jsonReader: {

repeatitems: false,

root: function (obj) { return obj.rows; },

page: function (obj) { return obj.pageindex; },

total: function (obj) { return obj.pagecount; },

records: function (obj) { return obj.total; }

},

prmNames: {

page: 'PageIndex',

rows: 'PageSize',

sort: 'Order',

order: 'Sort'

},

hidegrid: false,

rownumbers: true,

loadonce: false,

sortname: sortname,

sortorder: 'desc',

pager: "#" + gridPagerID,

viewrecords: true,

caption: caption,

toolbar: [true, "top"],

altRows: true,

//最后选中的行

onSelectRow: function (id) {

if (id && id !== lastsel) {

grid.jqGrid('restoreRow', lastsel);

lastsel = grid.jqGrid('getRowData', id)[sortname];

}

},

editurl: editurl

});

}

复制代码

其中要注意这两部分的参数,其中pagecount-json中代表页码总数的数据,total-json中代表数据行总数的数据,pageindex-json中代表当前页码的数据;prmNames则是重命名传到后台的分页参数名称;

传到后台的URL:GET /CountryHandler.ashx?_search=false&nd=1397394772871&PageSize=20&PageIndex=1&Order=ID&Sort=desc

复制代码

jsonReader: {

repeatitems: false,

root: function (obj) { return obj.rows; },

page: function (obj) { return obj.pageindex; },

total: function (obj) { return obj.pagecount; },

records: function (obj) { return obj.total; }

},

prmNames: {

page: 'PageIndex',

rows: 'PageSize',

sort: 'Order',

order: 'Sort'

},

复制代码

3:Html代码及JS代码:

复制代码

<head runat="server">

<title></title>

<link href="css/ui-lightness/jquery-ui-1.10.4.min.css" rel="stylesheet" type="text/css" />

<link href="css/ui.jqgrid.css" rel="stylesheet" type="text/css" />

<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>

<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>

<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>

<script src="js/myJqgrid.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function () {

showJqGrid();

});

function showJqGrid() {

var id = "gridTable";

var url = "CountryHandler.ashx";

var datatype = "json";

var colNames = ["ID", "名称","地址"];

var colModel = [

{ name: "ID", index: "ID"},

{

name: "SchoolName", index: "SchoolName", width: 200, align: "center"

},

{

name: "Address", index: "Address", width: 250, align: "center"

}

];

var caption = "学校列表";

var editurl = "CountryHandler.ashx";

var sortname = "ID";

var gridPagerID = "gridPager";

myJqGrid(id, url, datatype, colNames, colModel, caption, editurl, sortname, gridPagerID);

//initToolbar(id, gridPagerID);

}

</script>

</head>

<body>

<form id="form1" runat="server">

<table id="gridTable">

</table>

<p id="gridPager">

</p>

</form>

</body>

</html>

复制代码

4:后台的一般处理文件CountryHandler.ashx代码:

复制代码

using System.Web.Script.Serialization;

using ClassLibrary1;

using DAL;

namespace WebApplication1

{

/// <summary>

/// CountryHandler 的摘要说明

/// </summary>

public class CountryHandler : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

DAL.TestDbEntities contexts = new TestDbEntities();

context.Response.ContentType = "text/plain";

var quey = from School in contexts.T_School select School;

GridDatas model = new GridDatas();

int PageIndex= RequstString("PageIndex").Length == 0 ? 1 : int.Parse(RequstString("PageIndex"));

int PageSize=RequstString("PageSize").Length == 0 ? 20 : int.Parse(RequstString("PageSize"));

int TotalCount=quey.Count<T_School>();

model.pagecount = (TotalCount/PageSize).ToString();

model.pageindex = PageIndex.ToString();

model.total = TotalCount.ToString();

model.rows = quey.OrderBy(t=>t.ID).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();

JavaScriptSerializer serializer = new JavaScriptSerializer();

string Resul = serializer.Serialize(model);

context.Response.Write(Resul);

}

public static string RequstString(string sParam)

{

return (HttpContext.Current.Request[sParam] == null ? string.Empty

: HttpContext.Current.Request[sParam].ToString().Trim());

}

public bool IsReusable

{

get

{

return false;

}

}

}

public class GridDatas

{

public string pageindex { set; get; }

public string pagecount { get; set; }

public string total { get; set; }

public List<T_School> rows { get; set; }

}

}

复制代码

注意:同样借实体类GridDatas来实同JqGrid要求的JSON格式;转化成后的Json代码如下:

复制代码

{"pageindex":"1","pagecount":"10000","total":"200000","rows":[{"RelationshipManager":{},"ID":1,"SchoolName":"中学教育0","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":2,"SchoolName":"中学教育1","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":3,"SchoolName":"中学教育2","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":4,"SchoolName":"中学教育3","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":5,"SchoolName":"中学教育4","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":6,"SchoolName":"中学教育5","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":7,"SchoolName":"中学教育6","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":8,"SchoolName":"中学教育7","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":9,"SchoolName":"中学教育8","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":10,"SchoolName":"中学教育9","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":11,"SchoolName":"中学教育10","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":12,"SchoolName":"中学教育11","BuildDate":"\/Date

(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":13,"SchoolName":"中学教育踏浪帅

12","BuildDate":"\/Date(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":355},{"RelationshipManager":{},"ID":14,"SchoolName":"中学教育

13","BuildDate":"\/Date(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":15,"SchoolName":"中学教育

14","BuildDate":"\/Date(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":16,"SchoolName":"中学教育

15","BuildDate":"\/Date(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":17,"SchoolName":"中学教育

16","BuildDate":"\/Date(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390},{"RelationshipManager":{},"ID":18,"SchoolName":"中学教育

17","BuildDate":"\/Date(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":456},{"RelationshipManager":{},"ID":19,"SchoolName":"中学教育踏

浪帅18","BuildDate":"\/Date(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":456},{"RelationshipManager":{},"ID":20,"SchoolName":"中学教

育19","BuildDate":"\/Date(1393940972000)\/","Address":"厦门软件园","IsSenior":true,"StudentNum":390}]}

jqgrid 分页 (基于ashx)的更多相关文章

  1. JqGrid分页按钮图标不显示的bug

    开发中遇到的一个小问题,记录一下,如果有朋友也遇到了相同的问题,可以少走些弯路少花点时间. 如图: 分页插件使用了JqGrid,但是分页栏里出现了问题,上一页.下一页这些按钮的图标都显示为空,记得以前 ...

  2. jqGrid 分页

    这两天一直在搞jqGrid分页,焦头烂额,不过还是有点收获的(主要是后台分页):   jqGrid分页可以分为两种,远程数据(服务器数据)分页和本地数据分页,     先看远程数据分页:   $(&q ...

  3. jqGrid jqGrid分页参数+条件查询

    HTML <div class="row"> <div class="col-sm-20"> <form id="for ...

  4. jqgrid 分页时,清空原表格数据加载返回的新数据

    由于,我们是动态分页,分页后的数据是在触发分页后动态加载而来.如何使jqgrid清空原数据而加载新数据? 1)调用jqgrid的 clearGridData 方法清空表格数据 2)调用jqgrid的  ...

  5. 本地数据jqGrid分页

    var mydata=''; $(function() { var str = ''; str += "<span>共<span id='p_total'></ ...

  6. LayUI分页基于ASP.NET MVC

    ---恢复内容开始--- 今天写了挺久的分页,百度了很多都没有很好的.Net实例,今天我来更新一期关于layuiTable分页 首先你得理解layui的官方文档的Table分页部分,我在这里附上地址 ...

  7. 利用JqGrid结合ashx及EF分页显示列表之二

    上一篇文章简单利用JqGrid及ashx进行一个数据列表的显示,要文的重点是利用EF的分页与JqGrid进行结合,EF本文只是简单运用所以没有很规范,重点还是JqGrid分页的实现;本实例把JqGri ...

  8. Jqgrid的用法总结与分页功能的拓展

    这是本人写的第一个与技术相关的博客,但是非挑战技术的,而是对工作的总结,另外加一点点拓展. Jqgrid的功能十分强大,强大到可以做到与数据grid相关的任何功能,同时由于在用的过程中总是不能够一气呵 ...

  9. 利用JqGrid结合ashx显示列表之一

    最近项目决定运用JqGrid列表控件显示相关数据,以前接触比较多还是easyui和Ext.Net的列表控件,文章简单写的小实例进行一个总结: 1:引入相关的JS及CSS文件,JqGrid目前可以利用J ...

随机推荐

  1. xamarin Android activity生命周期详解

    学Xamarin我为什么要写这样一篇关于Android 的activity生命周期的文章 已经学Xamarin android有一段时间了,现在想起当初Xamarin也走了不少的弯路.当然Xamari ...

  2. linux防火墙之 ufw

    Usage: ufw COMMAND Commands: enable enables the firewall 开启ufw防火墙 disable disables the firewall 禁用防火 ...

  3. python 嵌套字典比较值,取值

    #取值import types allGuests = {'Alice': {'apples': 5, 'pretzels': {'12':{'beijing':456}}}, 'Bob': {'ha ...

  4. Java自己动手写连接池四

    Java自己动手写连接池四 测试: package com.kama.cn; import java.sql.Connection; public class Test { public static ...

  5. 有关opacity或RGBA设置颜色值及元素的透明值

    opacity声明来设置元素的透明值,当opacity设置元素的透明值,内部的文字及元素也会透明,通过RGBA设置的颜色值只针对当前元素,内部的文字及元素的透明值并未发生变化   opacity声明来 ...

  6. PHP字符串处理与正则表达式

    字符串 1. PHP中的字符串是一种基本数据类型,PHP对unicode没有本地支持. 2. 字符串可以可以通过花括号来访问每一个字符,并且每个花括号只能存放一个字符:     $str = 'abc ...

  7. Ruby学习之对象模型

    这两周工作内容较多,平时自己也有点不在状态,学的东西有点少了,趁着现在还有点状态,赶紧复习一下之前学习的Ruby吧. Ruby是我真正开始接触动态语言魅力的第一个语言,之前虽然也用过且一直用perl. ...

  8. Flask快速入门,知识整理

    一.Flask介绍(轻量级的框架,非常快速的就能把程序搭建起来) Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是 ...

  9. 记一次Hbase查询速度优化经历

    项目背景: 在这次影像系统中,我们利用大数据平台做的是文件(图片.视频等)批次的增删改查,每个批次都包含多个文件,上传完成以后要添加文件索引(文件信息及批次信息),由于在Hbase存储的过程中,每个文 ...

  10. golang 轮训加密算法

    Roy's friends has been spying on his text messages, so Roy thought of an algorithm to encrypt text m ...