Requesting page 0 in jqGrid
Is it possible to start from page=0 in a jqGrid?
I am working with data that is out of my control and when i request page 1 I actually get page 2 from the server, so therefore I am looking for some way to actually request page 0.
As far as i can see, setting the page parameter in the jqGrid options t开发者_运维问答o zero has no effect. When inspecting the request the page parameter is still 1.
I have also tried to change the page parameter later on after initialization. This sets the page to 1:
grid.setGridParam({page:0}).trigger('reloadGrid');
This on the other hand sets page successfully to 5 in the request:
grid.setGridParam({page:5}).trigger('reloadGrid');
I guess there is some check against requesting page 0 but any ideas on how to work around this?
If I understand your problem correct you can solve it by using serializeGridData event handler and page
property in the jsonReader defined as function.
I don't tested what you find below, but I hope either the code or a little modified code should work:
serializeGridData: function(postData) {
if (typeof(ts.p.postData.page) === "number") {
postData.page--; // decrease the value of page before sending to the server
}
return postData;
},
jsonReader: {
page: function (obj) {
return obj.page + 1; // increase the value of page returned from the server
}
}
It should be something like this:
grid.trigger("reloadGrid",[{page:1}]);
See Oleg's reply to a similar question.
UPDATE:
jqGrid pager starts from 1 and the method reloadGrid checks if the page is < 0, so it seems there's not much you can do.
精彩评论