Jqgrid - postData represents previous query parameters and data

I used postData to dynamically set request parameters. When I press any external button, I change the URL of the grid and also set some additional parameters in postData , as shown below. It seems that JqGrid adds all these parameters and data for all subsequent queries. Is there a way we can control or avoid sending these parameters 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 mail request: I see that the name , rate parameters go along with other standard jqGrid parameters such as sortname , sidx , rows , etc.

Now, if I click on the external button, if I change the URL of the grid, as shown 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 rate.html, say, for example, by clicking the refresh icon, jqGrid sends the previous msgIds parameter as well as the previous values. I do not want to send the previous request parameters to a new request when changing the URL. Is there a way we can achieve this?

+6
source share
3 answers

If I understand your problem correctly, you should avoid using setGridParam and do the following instead. You can use $('#grid').jqGrid("getGridParam", "postData") to get the link to the internal postData parameter. For instance,

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

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

+6
source

I had the same problem of saving postdata parameters from previous queries.

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

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

setting postData with new options =>

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

+1
source

I was able to solve it like this:

 function triggerRefresh(wsParams) { // determine ws path var myGrid=$('#myjsTreeView'); var urlData = "/myWebService.asmx/myWebServiceMethod"; // note: you need to pass url, datatype, postdata var gridParam = { url: urlData, datatype: "json", postData: wsParams, page: 1 }; myGrid.jqGrid('setGridParam', gridParam).trigger("reloadGrid"); } // function 

The difference is that I specify the datatype , url and page in general in my request, which made it work!

I call this function as follows:

 var myparams = $.toJSON({ para1: someValue, para2: someOtherValue }); triggerRefresh(myparams); 

when I need to update data. For example, omitting the data type will cause the update to fail.

0
source

Source: https://habr.com/ru/post/927895/


All Articles