I have a requirement below; I have a jqgrid that loads the json data using webservice(RESTful webservices) call.When form loads, i hit the server and load the data to grid.If i have 50 rows, the grid is loading 50 rows only.but i used pagination, so it will display only 10 records and click on next button in pagination other 10 records will displayed.But my requirement is on formload i should hit server and restric to display only 10 records.Then i click on Next again i call webservice call and display the next 10 rows.Is it possible?If yes, can share any samples?
1 Answers
Classical RESTful web services don't support pagination. So one have to return all data from the server and to use client side pagination. If you have only 50 rows of data I would recommend you to use client side pagination. You need just include loadonce: true
option to the jqGrid and all should already work. In general it's recommended to use loadonce: true
option if one loads not so many data from the server. There are not exist the exact limit of rows where client side pagination is preferred. It's about 1000 or 10000 rows of data. So in case of 50 rows of data it's really strictly recommended.
If you really need to implement server side pagination of RESTful services (in case of really large dataset) then your service have to support additional parameters of request which will be have no relation to resource URL. For example Open Data Protocol (OData) URI supports starting with version 2.0 (see here for example) parameters $orderby
, $skip
, $top
and $inlinecount
which could be appended to the URL to inform the server to return the data sorted by $orderby
. The returned data should contains only one page of sorted data based on the values of $skip
, $top
parameters. The URL looks like
http://host:port/path/SampleService.svc/Categories(1)/Products?$top=2&$orderby=Name
\______________________________________/\____________________/ \__________________/
| | |
service root URL resource path query options
The old answer provides an example of implementation jqGrid which calls Open Data Protocol (OData) web service. I used serializeGridData
callback to fill $top
, $skip
, $orderby
and $inlinecount
which "understands" OData web service. I used beforeProcessing
callback to total
property in based on count
property returned from the server because of usage $inlinecount: "allpages"
in the request. If the RESTful web services, which you use, supports OData too then you can use the same code.
-
Thanks for Reply Oleg...I struck with Jqgrid Pager.Say for Example,The request to server returns only first 10 rows of the data out of 20 in grid.i given rownum as 10 in jqgrid.so that time i am not able to click on next button to retrieve next 10 records.Is it possible to enable the next button in jqgrid pager ? – vik Nov 07 '14 at 13:49
-
@vik:You are welcome! I supposed, that the data returned from the server was in the wrong format. If you need implement paging on the server side the response have to contains `total` property (see [the documentation](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data)) which informs jqGrid about the total number of pages of the same size. – Oleg Nov 07 '14 at 14:01