using different params with the jqGrid api for paging
I'm using jqGrid with a restful api. By default when I click "next page", I get a url like:
http://mys开发者_运维问答ervice.com?rows=20&page=2
(I'm leaving out some params to keep the example simple.)
The service expects a url like:
http://myservice.com?limit=20&offset=2
What's the easiest way to set up that translation?
You want to set the prmNames
option. See the options documentation.
If your service has different parameters for pagination and sorting then you can manipulate the request URL in beforeRequest
event. I had to do this since my service accepts startIndex
and recordCount
.
beforeRequest: function() {
var postData = $('#mygrid').jqGrid('getGridParam', 'postData');
// add your pagination and sorting parameters here
postData.startIndex = postData.page * postData.rows - postData.rows;
postData.recordCount = postData.rows;
// delete parameters that you don't need
delete postData.page;
}
In the above code postData has query string parameters which get appended to the URL in case of GET request. If you have POST request containing JSON body then you can handle that too.
精彩评论