Search code examples
jqgrid

Create data url dynamically with jqgrid


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).


Solution

  • 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");