Reputation: 1289
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 the 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"?
Upvotes: 2
Views: 5747
Reputation: 222017
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';
...
Upvotes: 4
Reputation: 7735
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' }
});
Upvotes: 8