I am using the JQSuite's Trirand.Web.MVC dll for my integration of JQGrid into my MVC 3 application.
I am using the HTML helper for JQGrid, so in my View I have the following:
@Html.Trirand().JQGrid(Model.MyGrid, "Grid")
I know I can reload my grid on a button click by using the following code:
$("#Grid").trigger("reloadGrid");
This WILL reload the grid, calling the Action method I specified in my contoller code for setting up the JQGrid.
I have other controls on the page that I use for searching/filtering, these get passed to the action method fine.
I found the setGridParam method, which seems to indicate you can do something like:
$("#Grid").setGridParam({ someParam: 'blah' }).trigger("reloadGrid");
or this:
$("#Grid").jqGrid('setGridParam', { postData: { someParam: 'somevalue'} }).trigger("reloadGrid");
but my someParam parameter on my action method does not get filled with either method
How can I set these on the JQGrid so that they are picked up by Action method when doing the reload?
UPDATE: I have now tried this method for another parameter and it DOES work!
So now I have:
$("#Grid").jqGrid('setGridParam', { postData: {
someParam: 'somevalue',
paramTwo: ' some value',
paramThree: 'some other value'
} }).trigger("reloadGrid");
someParam does not work, but paramTwo and ParamThree DO work.
strange!
What could stop one parameter from working?
UPDATE2: Using Oleg's suggestion as follows:
var myGrid = jQuery("#Grid").jqGrid({
postData: {
someParam: function () { return $("#txtBox1").val(); },
paramTwo: function () { return $("#txtBox2").val(); },
paramThree: function () { return $("#txtBox3").val(); }
}
});
myGrid.trigger('reloadGrid');
...NONE of the values get sent through. I have validated the JQuery returns the correct values before it does the reload.
Right, many thanks to OLEG for his help as it led me to an answer!
The issue was "SomeParam" was already specified in the post data so I had to extend the existing data using this form:
this post helped me out with this, Oleg also posting over there too.
If I understand you correct you can use
postData
parameter to send additional parameters to the server. The most simple will be to usepostData
having methods (properties as functions):You can find more information here. In the case the current value will be read at any request to the action and the value will be send as additional parameter with the name
myCustomParam
.If you need to get the values of all control from the form you can use $.serializeArray function and send all results as one additional parameter.
You can get reference to
postData
parameter usinggetGridParam
and set/change new additional property. BecausegetGridParam
return the reference to it's internal parameters if you ask for object parameters you will don't need to usesetGridParam
.UPDATED: I don't know where your code are executed before the grid is created or after that. You can try the following code
I hope it will work in both cases.