[英]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.