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. js的Date对象

    1.构造Date对象 var dt = new Date(); //获取当地包含日期和时间的对象,格式为:Thu Aug 31 2017 09:15:43 GMT+0800 (中国标准时间) 2.使用 ...

  2. LAMP第三部分php,mysql配置

    php配置 1. 配置disable_functiondisable_functions = eval,assert,popen,passthru,escapeshellarg,escapeshell ...

  3. Linux命令每日一个

    2014-3-31 1:39 (1)tree linux以树状的结构显示当前目录及其包含的子目录下的文件 #apt-get install tree #tree   //在当前目录下直接使用该命令即可 ...

  4. Web开发入门学习笔记

    公司web项目终于要启动了,本以为django学习可以在实战中进行,结果最终使用了Drupal框架,好吧,那我们就PHP走起,买了本<细说PHP>,先跟着过一遍Web开发入门. HTTP协 ...

  5. 一种laravel特有的serviceProvider的加载方式

    这里的laravel版本5.5. 我是使用到dingo这个包的时候,觉得很奇怪,我们一般的包使用的时候都需要加载一个serviceProvider,提供服务,dingo/api这里也有ServiceP ...

  6. Invalid bound statement (not found): com.shizongger.chapter2.mapper.UserMapper.insertUser 解决方案

    在配置MyBatis时报错信息如下: Invalid bound statement (not found): com.shizongger.chapter2.mapper.UserMapper.in ...

  7. centos设置程序开机自启或禁止加载

    1. 可以直接把需要启动的脚本写到/etc/rc.d/rc.local文件里,例如 vim /etc/rc.d/rc.local /usr/local/apache/bin/apachectl sta ...

  8. 常见的DBCP连接池配置

    项目中使用mybatis出现一个问题,项目刚启动时,查询项目列表是ok的,过上一段时间之后,再次查询项目列表,查询失败,初步判断是因为mysql的连接问题,最后查阅资料,发现是连接池中的连接失效,导致 ...

  9. 8、ABPZero系列教程之拼多多卖家工具 添加手机注册登录功能

    现在网站基本都用手机注册,很少用邮箱注册,本篇内容比较多,代码我会尽量加备注,有些操作需要连续添加几个文件才不报错,如果VS显示错误,请继续后续步骤. 前面已经有一篇文章讲到集成短信发送模块:http ...

  10. sprintf的用法

    正文:printf 可能是许多程序员在开始学习C 语言时接触到的第二个函数(我猜第一个是main),说起来,自然是老朋友了,可是,你对这个老朋友了解多吗?你对它的那个孪生兄弟sprintf 了解多吗? ...