简体   繁体   中英

How to implement server-side paging in jqGrid using generic handler

i'm trying to implement paging for jqGrid. but it's not clear if i can do it using generic handlers in asp.net?

my grid looks like this:

layout:

<table id="userGrid" ></table>
<div id="userGridPager"></div>

script:

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));
}
}

i understand that i need to pass my data to client so that it will contain page, total, records for jsonReader, but i don't understand how to get page number in habdler. does anybody know the answer?

With this approach you could have the page number in the query string of the GET request Eg

WebApp/MyHanler.ashx?page=2

How to get query string parameter, you can see here: How to get the QueryString from an ashx file?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM