开发者

How do we clear grid parameters in jqgrid?

If I set the jqgrid parameters and then I again want to reset the parameters with new ones, without the old parameters being appended, how do I achieve that?

Lets say,for example:

Step 1: jQuery("#list").setGridParam({url:"testJsp.jsp",
                    mtype: "POST", 
                    postData:{xyz: '23fd', 
                              asd: 'were' }
                    });

Step2: jQuery("#list").setGridParam({url:"testJsp.jsp",
                mtype: "POST", 
                postData:{ert: 'trer', 
                          ghj: 'rew' }

                });

Now when I do this, by the end of "Step 2" I have a total of 4 parameters, including t开发者_运维问答he parameters from "Step 1". But I don't want this. After "Step 2" I just want to have the parameters of "Step 2".

Is there a way to clear the grid parameters between "Step 1" and "Step 2"?


Set postData to null before setting the new value. You don't have to redefine values for url and mtype if they're not changing.

jQuery("#list").setGridParam({postData: null});

jQuery("#list").setGridParam({postData: 
   {ert: 'trer', 
    ghj: 'rew' }
});


The expression jQuery("#list").jqGrid('getGridParam', 'postData') get you the reference to object which represent the postData. So you can work with it like with an object and add or delete properties whenever you need or not more need these:

var myGrid = jQuery("#list"),
    myPostData = myGrid.jqGrid('getGridParam', 'postData');

// next two lines are equivalent to
//    myGrid.jqGrid('setGridParam', 'postData', {xyz: '23fd', asd: 'were' });
myPostData.xyz = '23fd'; 
myPostData.asd = 'were';
...
delete myPostData.xyz;
delete myPostData.asd;
...
// next two lines are equivalent to
//    myGrid.jqGrid('setGridParam', 'postData', {ert: 'trer', ghj: 'rew' });
myPostData.ert = 'trer'; 
myPostData.ghj = 'rew';
...


You can use the GridUnload Method to clear the grid

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜