jQuery + jqgrid postData overriding default values

2019-02-19 11:09发布

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?

标签: jquery jqgrid
1条回答
贪生不怕死
2楼-- · 2019-02-19 11:54

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);
    }
});
查看更多
登录 后发表回答