I need to setup grid virtual mode, but data url should be prepared dynamically. More precisely I need to read the value from some input on the page and paste its value into data url. Unfortunately, there is only an example of grid virtual mode with static url (i.e. url itself is not formed dynamically).
Asked
Active
Viewed 521 times
1 Answers
0
It seems that it is possible to reassign data url like this:
$("#grid-id").jqGrid('setGridParam', { url: <new_url_here> }).trigger('reloadGrid');
Thanks to Oleg I found more elegant solution. When initializing grid I need to specify postData parameter like this:
$("#grid").jqGrid({
url: <url_without_parameters>,
postData: {
fileName: function() { return $("#input").val(); }
},
...
});
And to refresh grid I need to make the following call:
$("#grid").trigger("reloadGrid");

Denis Murashov
- 43
- 1
- 9
-
Mostly it's better to use `postData` (see [here](https://stackoverflow.com/a/2928819/315935)), which adds dynamic parameters to the base URL. There are more options to generate `url` dynamically, but one one should know more details about the usage of jqGrid. An example of URLs, which you need to generate, would be good. – Oleg Aug 12 '18 at 18:37
-
Thank you for your answer. On my page I have input, which contains file name, and the url looks like this: `http://localhost/Log/GetLogEntries?fileName=
`. To send file name as parameter I use encodeURIComponent function. – Denis Murashov Aug 14 '18 at 15:13 -
Try to use `url: "http://localhost/Log/GetLogEntries", postData: { fileName: function () { return "
"; } }`. If you use HTTP GET then it will be the same and you can include more logic in the function `postData.fileName`. The `postData` will be forwarded as `data` parameter of `jQuery.ajax`, which will call internally [jQuery.param](http://api.jquery.com/jquery.param/), which will call `encodeURIComponent` internally. Thus one don't need to call `encodeURIComponent` inside of the function `postData.fileName`. – Oleg Aug 14 '18 at 15:47