I'm not sure that the construct with such caching of the data is good, but nevertheless your current problem is clear.
It's important to understand that the call
$("#list").jqGrid({
url:indexObj.gridUrl,
...
});
creates the grid. It converts empty <table id="list"></table>
in very complex structure of divs and tables. So one can create the grid only once.
The grid consist from many parts (like headers) which don't need be recreated on the next filling of the grid. So jqGrid provides reloadGrid
event which can be triggered to refill the body of the grid. If jqGrid have postData
with some value like
postData: {
limit: limitVar
}
then if means that the object value of postData
will be created and initialized once with the current value of limitVar
variable. If you have outer variable (global, or defined in some outer scope) then you can use
postData: {
limit: function () { return limitVar; }
}
In the case you will have the current value of limitVar
as the value of limit
parameter of URL. By the way if the user just click on the column header, the grid need be sorted and jqGrid will make new HTTP request to url
. If you use function
inside of postData
then you will have the current value of limitVar
in the cases too.
If you will make less modification in your existing code then you can replace the line $("#list").trigger("reloadGrid");
(which is absolutely unneeded in the current code) to
$("#list").jqGrid("GridUnload");
It will destroy previously created structure of dives and tables (which build the grid) and creates an empty <table id="list"></table>
on the same place. So you can recreate the grid. Such code will work not so effectively, but it could be very helpful in some scenarios (see the answer and this one for example).