Search code examples
jqgrid

How to pass extra parameter to Add and Edit url in jqGrid


Order id is stored in variable _documentId and changed in runtime by ajax call if new order is saved to actual it.

If adding new detail row to jqGrid Add form url or inline Edit url reqires this id also. I tried to use postdata but _documentId is not passed if Edit and Add urls are called. How to pass _documentId value to those urls ?

   var _documentId; // assigned from ajax call after save.

   $(function () {
        var grid = $("#grid");
        grid.jqGrid({
            postData: {_documentId: function() { return _documentId } },
            editurl: 'Edit',  // How to pass _documentId value to this controller ?

            url: 'GetData',
            datatype: "json",
            mtype: 'POST',
            scroll: 1,
            multiselect: true,
            multiboxonly: true, 
            scrollingRows : true,
            autoencode: true,
            prmNames:  {id:"_rowid", oper: "_oper" }, 
            colModel: <%= Model.ColModel() %>,
            gridview: true,
            toppager: true,
            viewrecords: true
            });

      grid.navGrid("#grid_toppager", {}, {}
        { url: 'Add' }  // How to pass _documentId value to this controller ?
      );                

Solution

  • In case of form editing, you should use editData parameter to send additional data to the server. Another way is to modify the postdata inside of onclickSubmit or beforeSubmit event handler. You can of course do it in the serializeEditData event handler instead. Using onclickSubmit, you can easy modify the URL (params.url) if you need really place the information in the URL and not in the data which will be send to the server.

    In case of inline editing, you can use extraparam parameter of the editRow or use serializeRowData event handler.