I am trying to figure out how to user the paging functionality of the jqGrid.
Currently I am stuck on Page 1 of 4. No matter if I press the Next button or not. It just stays on 1.
I am using ASP.Net with a webservice to populate my JSON data. How do capture the event from the client to populate the property on the webservice to bring back the correct value?
Any help is appreciated.
If one press “Next” button a new request will be send to the server. The request will contain
page=2and, for example,rows=10parameters as a part of URL (if one want to get next 10 rows of the second page).Your server code should read this parameters and send back the corresponding data rows. The JSON data send back from the server should look like following
(see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data). So the data must contain the correct value for the
page(page=2). In general it is possible, that now you have less data as before and you give back the page number 1 on the request to get the page number 2.So I suggest that currently your server code don’t give back the correct value of
pagein the output.UPDATED: OK Jeff. I continue my answer in jqgrid setGridParam datatype:local and post how is promised a code how do server side paging, sorting and searching (or advanced searching).
First of all in the example I will not really implement sorting and searching and only simulate paging where you have problem now. The real paging, sorting and searching should be implemented as the corresponding
SELECTstatements to SQL database where the data exists. The sorting follow to theORDER BY, searching toWHEREand paging to constructions likeTOP(x),TOP(x)withLEFT OUTER JOINor the usage ofROW_NUMBER() OVER(...)constructs. But these all are not the subject of your question. So I reduce all to the simple simulation of data paging.I start with the code of the ASMX Web Method:
where classes
JqGridDataandTableRoware defined like following:We skip any verification of input parameters of the
TestMethodto make the code example more readable.Now the client code:
In the code I use the same technique like in jqgrid setGridParam datatype:local but the code of
serializeGridDatafunction is a little different. Because we use POST and not GET method to get the data from the server all input parameters of the web method must be always set. On the other side jqGrid set not always parameterssearchField,searchOperandsearchString, but only if_search=true. For example at the first load of jqGrid, the_search=falseandsearchField,searchOperandsearchStringare not defined in thepostData. To fix the problem we initialize undefined parameters withnull.To implement sorting one needs to use
sidx(sort index) andsord(sort direction:"asc"or"desc") parameters.To implement searching one needs to use other parameters
_search,searchField,searchOper,searchString.During advanced searching instead of
searchField,searchOper,searchStringparameters the parameterfiltersmust be used (see commented lines). The data must be decoded with respect of a JSON deserializer. So must be setmultipleSearch : truein the jqgrid. TheserializeGridDatafunction should be replaced toand the prototype of the web method should be changed to
to decode the parameter
filtersone can use such simple code:where the class
jqGridSearchFiltercan be defined like following:I hope this information will be enough for you to implement any kind of jqGrid usage with respect of ASMX Web Method.
I used here a simplest data send from server to the client with additional
idoutside of the main data. If one of the columns which you have in the table is theid, you can a little reduce the data send to the server. See Jqgrid 3.7 does not show rows in internet explorer for more details.