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. TensorFlow文档翻译-01-TensorFlow入门

    版权声明:本文为博主原创文章,转载请指明转载地址 http://www.cnblogs.com/junyang/p/7429771.html TensorFlow入门 英文原文地址:https://w ...

  2. bzoj 2752: [HAOI2012]高速公路(road)

    Description Y901高速公路是一条重要的交通纽带,政府部门建设初期的投入以及使用期间的养护费用都不低,因此政府在这条高速公路上设立了许多收费站.Y901高速公路是一条由N-1段路以及N个收 ...

  3. vue有关小知识

      截取链接参数: //截取链接参数 this.id = this.$route.query.id;

  4. 基于编辑距离来判断词语相似度方法(scala版)

    词语相似性比较,最容易想到的就是编辑距离,也叫做Levenshtein Distance算法.在Python中是有现成的模块可以帮助做这个的,不过代码也很简单,我这边就用scala实现了一版. 编辑距 ...

  5. java自动化测试-http请求post

    继上文的get请求http://www.cnblogs.com/xuezhezlr/p/7667995.html的简单讲解后,这篇文章大概说一下我所遇到的主要的post请求以及他的测试代码 上文介绍到 ...

  6. vue实现登录后跳转到之前的页面

    在开发中我们经常遇到这样的需求,需要用户直接点击一个链接进入到一个页面,用户点击后链接后会触发401拦截返回登录界面,登录后又跳转到链接的页面而不是首页,这种问题该如何去做呢? 先说一下我们需要用到的 ...

  7. 一图看懂java内存模型

    熟话说一张好图胜过千言万语,在此便将java内存模型重新整理了一次,将细节标注到图中献给需要的同学:

  8. 通过tokenPlease()函数获取accessToken

    作者:陈希章 发表于 2018年1月5日 这是一个很小的技巧,而且用几句话就能讲明白.事情是这样的,我最近在回顾之前写过的文章:通过其他第三方工具体验Microsoft Graph 的时候,发现最近的 ...

  9. [js高手之路] es6系列教程 - Map详解以及常用api

    ECMAScript 6中的Map类型是一种存储着许多键值对的有序列表.键值对支持所有的数据类型. 键 0 和 ‘0’会被当做两个不同的键,不会发生强制类型转换. 如何使用Map? let map = ...

  10. Java的类的实例化顺序

    Java的类的实例化顺序 父类的静态数据 子类的静态数据 父类的成员变量 父类的构造方法 子类的成员变量 子类的构造方法