Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqgrid - postData submits previous request params and data

Tags:

jquery

jqgrid

I have been using postData to set the request params dynamically. On click of some external button, I change the grid URL and also set some additional params in postData like below. JqGrid seems to append all these params and it's data for all the subsequent requests. Is there a way we can control or avoid these params being sent every time?

My grid definition:

jQuery(function() {
    $('#grid').jqGrid({
    url: 'rates.html',
    postData: {
        name: function() { return $("#name").val(); },
        rate: function() { return $("#rate").val(); },
                .....
        }
        ....
    });
});

Here in the post request: I see that name, rate params are going along with other standard jqGrid parameters like sortname, sidx, rows, etc...

Now if on click of an external button, if I change the grid URL like below

$('#changeReqBtn').click(function() {
       $('#grid').setGridParam({ url: 'changeReq.html', 
                              postData: { msgIds: msgIds } });
       $('#grid').trigger("reloadGrid");     

});

Now jqGrid sends name, rate, msgIds params

Now if I change the URL back to rates.html say for example, on click of refresh icon, jqGrid sends the previous msgIds param and also the previous values. I don't want to send the previous request params in the new request when the URL changes. Is there a way we can achieve this?

like image 360
varaprakash Avatar asked Oct 17 '12 03:10

varaprakash


2 Answers

If I correct understand your problem you should avoid usage of setGridParam and do the following instead. You can use $('#grid').jqGrid("getGridParam", "postData") to get the reference to the internal parameter postData. For example,

var myPostData = $('#grid').jqGrid("getGridParam", "postData");

So you can use delete myPostData.msgIds to delete any property of the method previously added by setGridParam.

like image 104
Oleg Avatar answered Oct 23 '22 14:10

Oleg


I had the same issue of preserving postdata parameters from previous requests.

I fixed it by clearing postData first and then setting postData with new parameters.

clearing postData => $('#grid1').setGridParam({ postData: ""});

setting postData with new parameters =>

var formValues = {searchVal: "abc", country: "US"} $('#grid1').setGridParam({ postData: formValues});

like image 28
Mahesh Avatar answered Oct 23 '22 15:10

Mahesh