5

I need to add additional dynamic parameter to jqGrid's POST data when I'm adding new record with modal form.

I tried:

$('#table').setPostData({group: id});
$('#table').setPostDataItem('group', id);
$('#table').setGridParam('group', id);

and nothing worked out.

Teneff
  • 30,564
  • 13
  • 72
  • 103

2 Answers2

10

you can use editData parameter of the editGridRow method. In the most cases you use editGridRow not directly, but using Navigator. In the case you can define editData as the part of prmEdit or prmAdd of the navGrid:

$('#table').jqGrid('navGrid','#pager',
                   {/*navGrid options*/},
                   {/*Edit options*/
                       editData: {
                           group: function() {
                               return id;
                           }
                       }
                   }
});

One more option is the serializeEditData, onclickSubmit or beforeSubmit method. See details here and here.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thanks, it helped me a lot, but actually I set it as add options param – Teneff May 31 '11 at 08:27
  • 2
    @Teneff: You are welcome. The setting of the "Add" option works exactly in the same way (the next `prmAdd` parameter of `navGrid`), but I am sure you found this already yourself. – Oleg May 31 '11 at 09:20
  • @Oleg: Can we call navGrid in runtime so I can add data to the editData field? Would it overwrite any preset settings in navigator? – Quincy Jun 23 '11 at 08:41
  • 2
    @Quincy: You can't overwrite the `navGrid` parameters with the second cal of `navGrid`. If you would use `editData: myEditData`, where `myEditData` is an object (defined at least as `var myEditData={};`) you will be able to add, modify or remove the properties of `myEditData`. – Oleg Jun 23 '11 at 09:37
  • @Oleg: Do you mean I must pass an object as parameter in order to add new data into editData? Because I was trying to add something to editdata by putting {newdata:'something'} as the editData param when I call navGrid the 2nd time but seems nothing has changed. – Quincy Jun 23 '11 at 09:52
  • 2
    @Quincy: Yes! In must be a variable with the object (like `myEditData` see above) as a value instead of inline syntax `{...}`. In the case the `navGrid` will receive **the reference** to the object `myEditData`. So I hope (but not tested myself) that you will be able to modify `myEditData` and the `navGrid` will use it in the modified form. – Oleg Jun 23 '11 at 10:08
  • @Oleg: Ok thanks I will give it a try. If you have time please check out my other question (probably related) http://stackoverflow.com/questions/6452368/retrieving-grid-in-form-editing-events-in-jqgrid – Quincy Jun 23 '11 at 10:11
8

You can add additional dynamic parameter to jqGrid's POST data

$j("#listsg11").jqGrid({
    url: "/summary_reports",   
    postData: {department:"value1", score_r1:"value2", designation:"value3" },
    mtype: 'POST',
    datatype: "xml",
    height: 250,
    width: '100%', .... and so on

This method appends values with default params (used by jqGrid) with call.

Abdul Basit
  • 189
  • 2
  • 8