I generate my jqgrid from model class which I pass into view. I get constructed and working jqgrid. However, I want to set postData on one view, where I use jqGrid, from script in that view, after I call helper for creating jqgrid, without having to change whole partial view which creates jqgrid.
I tried running
$("#@Model.Id").jqGrid('setGridParam', { postData: { test: 233} });
and
$("#@Model.Id").setGridParam({ postData: { test: 233} });
but without error or any result. If I set postData in jqgrid parameters (in partial view where it is constructed, it works.
I also checked that grid exists, added
console.log($("#@Model.Id").size());
before the first line, and it shows 1.
UPDATE: This .setGirdParam function started to work for me for no apparent reason, so I will accept answer if someone can give some insight what can prevent this from working. Thanks
You didn't include the definition of jqGrid in your question and we can't see the place where the
setGridParam
is called. First of all you should usesetGridParam
after the jqGrid is created, but before the request will be sent. If you will change thepostData
the next jqGrid request can use the new parameter. So one typically usessee here.
I suppose that the best option for you will be the usage of function
test
property of thepostData
as the function:See here for details. In this way you can implement practically any scenario.
By the way if you don't want that jqGrid to send any request to the server till the event is happened you can use
datatype:'local'
at the initialization time. Then if you want that the grid should be filled you can usesetGridParam
to change thedatatype
from'local'
to'json'
(or'xml'
) and call.trigger('reloadGrid',...)
.Here is the method i used