Faiyet
Faiyet

Reputation: 5471

jqgrid keeps custom post parameters on reload

So I have a date picker and a select-list. Then a jqgrid, working fine, filtering and all. This is what I am doing.

$("#sessSearch").unbind('click').on('click', function(){
    var mydate = $("#sessSelector").val();
    var mytype = $("#sess_type :selected").val();
    if(mydate && mytype){
      $("#listSESS").jqGrid('setGridParam',{postData:{sess_date:mydate, sess_type:mytype}}).trigger("reloadGrid");  
    }else{
        alert("The search form is incomplete");
    }                                    
    $("#sessSelector").val('');
    $("#sess_type").val('');
});

What is happening there is I am sending along the values of my selectlist and datepicker along in the postData for the jqgrid. Only when the search button is clicked. So far so good. I can get the values on the serverside. The problem is when I click the refresh button on the grid pager, the previously sent paramiters remain in the postData. See below, firebug showing all post parameters.

The first is a normal default load, works fine.

The second happens after using my search form and adding to the postData and then I clicked on the refresh button the grid pager.

enter image description here

How do I reset the postData for the grid native reload mechanism to exclude my custom parameters? My custom paramiters must only go in when I tell it to go in.

Please advise.

Upvotes: 1

Views: 2308

Answers (2)

Faiyet
Faiyet

Reputation: 5471

Thank you so much Oleg, I basically disabled the default refresh action and did this with the pager. So my custom search sends the parameters only when my search mutton is clicked.

jQuery("#listSESS").jqGrid('navGrid','#pagerSESS',{edit:false,add:false,del:false,search:false, refresh:false},
    {}, // edit options
    {}, // add options
    {}, // del options
    {}  // search options        
);
$("#listSESS").jqGrid('navButtonAdd', "#pagerSESS", {
     caption: "", title: "Reload Grid", buttonicon: "ui-icon-refresh",
     onClickButton: function () {
        var mypostData = $("#listSESS").jqGrid("getGridParam", "postData");
        delete mypostData.sess_date;
        delete mypostData.sess_type;
        $("#listSESS").jqGrid('setGridParam',{postData:mypostData}).trigger("reloadGrid");
     }
});

works like a charm.

Upvotes: 0

Oleg
Oleg

Reputation: 221997

You can use getGridParam to get reference on internal object postData. The object have properties sess_date and sess_type with the values from the last setGridParam call. One can use delete to remove property from an object. So the following code should work

var postData = $("#listSESS").jqGrid("getGridParam", "postData");
delete postData.sess_date;
delete postData.sess_type;

Upvotes: 1

Related Questions