How to install postData in jqgrid AFTER it was created?

I am creating my jqgrid from a model class that I am passing into view. I get a built and working jqgrid. However, I want to set postData in one view, where I use jqGrid from a script in that view after I call the helper to create jqgrid without changing the whole partial view that jqgrid creates.

I tried to run

$("#@Model.Id").jqGrid('setGridParam', { postData: { test: 233} }); 

and

 $("#@Model.Id").setGridParam({ postData: { test: 233} }); 

but without errors or any result. If I set postData in jqgrid parameters (in the partial view where it is built, it works.

I also checked that the mesh exists, added

 console.log($("#@Model.Id").size()); 

before the first line, and it shows 1.

UPDATE: this .setGirdParam function started working for me for no apparent reason, so I will accept the answer if someone can give some idea of ​​what might prevent this from working. Thanks

+7
source share
3 answers

You did not specify a jqGrid definition in your question, and we cannot see the place where setGridParam is setGridParam . First of all, you should use setGridParam after the jqGrid created, but before the request is sent. If you change postData , the following jqGrid query may use the new parameter. So commonly used

 $("#@Model.Id").trigger('reloadGrid', [{page:1}]); 

see here .

I believe that the best option for you would be to use the test property of the postData function as a function:

 $("#@Model.Id").jqGrid({ // ... other jqGrid parameters ... postData: { test: function() { // the code can by dynamic, read contain of some elements // on the page use "if"s and so on and return the value which // should be posted to the server return 233; } } // other jqGrid parameters ... }); 

See here for more details. This way you can implement almost any scenario.

By the way, if you do not want jqGrid to send any request to the server until the event occurs, you can use datatype:'local' during initialization. Then, if you want the grid to be filled, you can use setGridParam to change the datatype from 'local' to 'json' (or 'xml' ) and call .trigger('reloadGrid',...) .

+11
source
 $("#grid id").setGridParam({ postData: {data:dataval} }); $("#grid id").trigger('reloadGrid', [{page:1,data:dataval}]);ntn 
+1
source

Here is the method I used

 postData: { 'testKey': function () { return 'testvals'; } }, 
+1
source

All Articles