2

below is my jqgrid code

 $(function() {
        jQuery("#jsonmap").jqGrid({
        url: 'Handler.ashx',
            datatype: "json",
            colNames: ['Inv No', 'Name','Email'],
            colModel: [{ name: 'id', index: 'id', width: 100},
              { name: 'name', index: 'name', width: 200 },
              { name: 'email', index: 'email', width: 200}],
              rowNum: 10, rowList: [10, 20, 30],
              pager: '#pjmap',
              sortname: 'id',
              viewrecords: true, sortorder: "desc",
              jsonReader: { repeatitems: false, id: "0" },
                  caption: "JSON Mapping", height: '100%'
              }); 
          jQuery("#jsonmap").jqGrid('navGrid', '#pjmap', { edit: false, add: false, del: false,search:false }); 
            });
  • My json data:

{"page": 1,"total": 2,"records": 15,"rows": [{"id": 1, "name":"giri", "email":"giri"}, {"id": 2, "name":"ravi", "email":"giri"},{"id": 3, "name":"kumar", "email":"giri"}, {"id": 4, "name":"raju", "email":"giri"}, {"id": 5, "name":"madhu", "email":"giri"},{"id": 6, "name":"vivek", "email":"giri"}, {"id": 7, "name":"radha", "email":"giri"}, {"id": 8, "name":"krishna", "email":"giri"}, {"id": 9, "name":"raghu", "email":"giri"}, {"id": 10, "name":"bhaskar", "email":"giri"}, {"id": 11, "name":"bhaskar", "email":"giri"}, {"id": 12, "name":"bhaskar", "email":"giri"}, {"id": 13, "name":"bhaskar", "email":"giri"}, {"id": 14, "name":"bhaskar", "email":"giri"}, {"id": 15, "name":"subbu", "email":"giri"}]}

paging is not working .Can anyone tell me what is the mistak ? Thank you...

Rafay
  • 30,950
  • 5
  • 68
  • 101
user601367
  • 2,308
  • 12
  • 34
  • 44

1 Answers1

2

The url which you use in the jqGrid will be appended with the information about the required page. You need use QueryString collection of the HttpContext to get the parameters. After that you have to implement the paging of data on the server side.

public class Handler : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        string pageToLoad = context.Request.QueryString["page"];
        string rowsPerPage = context.Request.QueryString["rows"];
        string sortIndex = context.Request.QueryString["sidx"];
        string sortDirection = context.Request.QueryString["sord"]; //"asc" or "desc"
        ...
    }
}

If the user click on next/previous page button of grid of if the user click on the column header to sort the data the new request will be send to the server. So in case of the usage datatype:'json' or datatype:'xml' the server is responsible to provide of data from the correct page. Before paging the data should be previously sorted.

If you have problem to implement data paging on the server side you can return all data and include loadonce:true in the list of jqGrid parameters. You should understand that in the case usage loadonce:true the data will be loaded from the server only once. After the first load the datatype parameter will be changed to 'local'.

I recommend you (if it is possible) to use ASMX web services or more better WFC service as a part of your web instead of usage very old technique of ASP.NET Web Handler (ashx).

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • how to use: string pageToLoad = context.Request.QueryString["page"]; string rowsPerPage = context.Request.QueryString["rows"]; string sortIndex = context.Request.QueryString["sidx"]; string sortDirection = context.Request.QueryString["sord"]; to fetch only those perticular values – user601367 Feb 23 '11 at 14:16
  • @user601367: Sorry, but I don't understand your question. What "perticular values" you mean? If you append (modify) you question with the code fragment which you currently use many thing will be more clear. The problem should be solved in the server code, but you don't posted any server code. – Oleg Feb 23 '11 at 14:26
  • public class Handler : IHttpHandler { public void ProcessRequest (HttpContext context) { string pageToLoad = context.Request.QueryString["page"]; string rowsPerPage = context.Request.QueryString["rows"]; string sortIndex = context.Request.QueryString["sidx"]; string sortDirection = context.Request.QueryString["sord"]; //"asc" or "desc" ... } } In the above code their are 4 variables pageToLoad ,rowsPerPage ,sortIndex ,sortDirection ....how to use these variables to fetch values for 2nd page ??? – user601367 Feb 23 '11 at 14:27
  • @user601367: Sorry, but it is my code, because I don't has any your code. What is not working? Do you use MS SQL Server on the server side? Which kind of data access you use: `SqlDataReader`, LINQ to SQL, Entity Framework, ... ? Do you know how select with the data paging can be implemented in the data access technology? – Oleg Feb 23 '11 at 14:33
  • i am using sql server 2008 and i am building json string...i am fetching data at once and building json string ...so my question is how to filter data in json using pageToLoad,rowsPerPage ,sortIndex ,sortDirection for every page change – user601367 Feb 24 '11 at 04:59
  • @user601367: Look at the code from the old answer http://stackoverflow.com/questions/4078592/sortable-jqgrid-using-linq-to-mysql-dblinq-and-dynamic-linq-orderby-doesnt-w/4079121#4079121 – Oleg Feb 24 '11 at 08:43