2

so I have grid which I set some defaults on like so...

defaults: {
    datatype: "json",
    mtype: "POST",
    autowidth: true,
    height: '100%',
    viewrecords: true,
    loadonce: false,
    rowNum: 100,
    rowList: [15,30,50,100,200,500]
},

then depending on the page being loaded I set the colModel and then finally few other things like follows:

var fields = $(":input").serialize(); //into post data..

jQuery('#'+$Global.trxGrid.gridId)
    .setGridParam({
        url : page,
        postData : fields,
        loadError: function(xhr,st,err) {
            $('#searchErrorText').text('Please try again later.');
            $('#searchErrorDialog').dialog('open');
        },
        ajaxGridOptions: {
            timeout: 150000
        }
     }
 );

but when I inspect the postData the prmNames are not there (_search=false&nd=1324619663709&rows=100&page=1&sidx=&sord=asc) etc. If I comment out the postData in the above method then they appear. Does the postData override everything? If so I guess I need to append as oppose to override but I can't find any clean way to do this. Can someone suggest a solution or am I doing something wrong?

Green Day
  • 654
  • 1
  • 8
  • 17

1 Answers1

5

you have to add a extra option to your options called serializeGridData see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events

so you should do something like this:

$('#grid').jqGrid({
    url: 'url',
    ....
    serializeGridData: function(postData) {
      var newPostData = $.extend(postData, {
        extraParam: 'EXTRA-PARAM-VALUE'
      });

      // newPostData now is (_search=false&nd=1324619663709&rows=100&page=1&sidx=&sord=asc&extraParam=EXTRA-PARAM-VALUE)
      return $.param(newPostData);
    }
});
Manuel van Rijn
  • 10,170
  • 1
  • 29
  • 52
  • 1
    +1 from me. I agree with your suggestion. Some small remarks: I find better to use `$.extend({}, postData, {extraParam: 'EXTRA-PARAM-VALUE'});` instead of `$.extend(postData, {extraParam: 'EXTRA-PARAM-VALUE'});` because `$.extend` modifies the first parameter. Using `$.extend({}, ...` holds `postData` parameter unchanged. Another remark: `return $.param(newPostData);` do the same as `return newPostData;` because `$.ajax` call `$.param` automatically. So `serializeGridData` can be like `serializeGridData: function (postData) { return $.extend(postData, {extraParam: 'EXTRA-PARAM-VALUE'}); }` – Oleg Dec 24 '11 at 11:01