[英]How to implement server-side paging in jqGrid using generic handler
我正在尝试为jqGrid实现分页。 但是尚不清楚我是否可以在asp.net中使用通用处理程序来做到这一点?
我的网格看起来像这样:
布局:
<table id="userGrid" ></table>
<div id="userGridPager"></div>
脚本:
grid = $("#userGrid");
grid.jqGrid({
url: 'http://localhost/MyApp/MyHandler.ashx',
datatype: "json",
colNames: ['Id', 'Name', 'Account', 'Deleted', 'Timer'],
colModel: [
{ name: 'Id', index: 'Id', width: 50, stype: 'text', key: true },
{ name: 'Name', index: 'Name', width: 150, editable: true},
{ name: 'Account', index: 'Account', width: 50, editable: false },
{ name: 'Deleted', index: 'Deleted', width: 50, editable: true, sortable: false, align: 'center', edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", formatoptions: {disabled : false} },
{ name: 'Timer', index: 'Timer', width: 80, align: "right", editable: true }
],
rowNum: 15,
mtype: 'GET',
pager: '#userGridPager',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption: "Users",
height: "100%"
});
MyHandler.ashx:
public class MyHandler: IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
// how can i get here page number?
var users = User.GetAllUsers(); // it's necessary to pass page number and page size to this function
var jsonSerializer = new JavaScriptSerializer();
context.Response.Write(jsonSerializer.Serialize(users));
}
}
我知道我需要将我的数据传递给客户端,以便它包含jsonReader的页面,总计,记录,但是我不知道如何在habdler中获取页面号。 有人知道答案吗?
通过这种方法,您可以在GET请求的查询字符串中具有页码,例如
WebApp/MyHanler.ashx?page=2
如何获取查询字符串参数,您可以在这里看到: 如何从ashx文件获取QueryString?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.