I need to load my grid from a server that expect a URL + parameters + a serialized payload, i.e. the message body. I am using a POST method and the server expects this along with JSON payload.
The serialized payload is a JSON string for MongoDB that instructs mongo how to find the data we care about. I designed the RESTful interface to respond back in the JSON format that jqGrid expects, however, to use pagination, I expected jqGrid to append the values for "page", "rows", etc, etc as a query string: baseURL?rows=10&page=1
Here is my grid setup
grid.jqGrid({
ajaxGridOptions: {
contentType: "application/json",
},
altRows: true,
autoWidth: true,
caption: "Results for " + ADC_Idl.buildQueryTitle(),
colNames: displayNames,
colModel: columnModel,
datatype: "json",
height: "auto",
mtype: "POST",
pager: '#pager5',
//postData: ADC_Idl.buildQueryPayload(),
serializeGridData: function (postData) {
grid.jqGrid("setGridParam", "url", ADC_Idl.buildQueryURL() + "?" + jQuery.param(postData));
return ADC_Idl.buildQueryPayload();
},
beforeRequest: function() {
grid.jqGrid("setGridParam", "url", ADC_Idl.buildQueryURL() + "?page=" +
grid.jqGrid("getGridParam", "page") + "&rows=" +
grid.jqGrid("getGridParam", "rowNum") );
},
rowList: [10, 20, 30],
rowNum: 10,
url: ADC_Idl.buildQueryURL(),
viewrecords: true,
jsonReader: {
repeatitems: false
}
I've left a few things in there to show what I have tried. I tried having the serializedGridData function update the URL, with no luck, for whatever reason it seems to be ignored. I tried updating the URL before the request, still no luck.
Originally I just set postData = serialized data, assuming the default pagination parameters would still be appended. This was not the case.
The documentation for postData just says "See API methods for manipulation" with no link (NO LINK IN A WIKI??!!! come on!!)
I've read every Oleg answer I could find here, nothing seems to address this scenario, which I find hard to understand, this must be a pretty common usecase.
This is how my server responds to the initial request for data (no pagination needed)
page: 1
records: 500
rows: [{_id: 1, REALM: "example.com", ACCOUNT: "8561000000",…},…]
total: 50
truncated for brevity.
After three days of trying everything I can think of, I'm pleading for some jqGrid experts to help!!
Thanks!
UPDATE
Figured it out and comments from Oleg made it even better. Posted as Answer!