0

I want to reload jqgrid with new parameters.I'm using .setPostData().Please look at my code below.It always give me error at .setPostData().M I missing something? format?

$('table[id$="'+tabID+'_BBGrid"]').jqGrid({ 
    url:'/Controls/Advertiser/BBControlNew.ascx.ashx?action=getBBData&advertiserID=' + $('#advertiser_id').text() + '&startDate=' + $('input[id$="' + tabID +
 '_FromCalBuyBack_CalendarTbx"] ').val() + '&endDate=' + $('input[id$="' + tabID + '_ToCalBuyBack_CalendarTbx"] ').val(),
    datatype: 'json',
    mtype: 'POST', 
    height:'100%',
    width:'100%',
    colNames: result.colNamesData, 
    colModel: result.colModelData,
    //pager: '#RequestLeadspager', 
    rowNum : 100,
    shrinkToFit :false,
...........
function  BuyBackGridReload(tabID,NoSelectedValues)
{
    $('table[id$="'+tabID+'_BuyBackGrid"]').setPostData({
        advertiserID:$('#advertiser_id').text(),
        CampaignsDdlSelectedValue: $('select[id$="CampaignDdl"] option:selected').val(),
        startDate: $('input[id$="'+tabID+'_FromCalBuyBack_CalendarTbx"] ').val(),
        endDate: $('input[id$="'+tabID+'_ToCalBuyBack_CalendarTbx"] ').val(),
        NoSelectedValue: NoSelectedValues
    }).trigger("reloadGrid");
};

I have search btn.I'm getting values for NoSelectedValues inside that search btn. here is the code for button click. $('input[id$="'+tabID+'_BuyBackSearchBtn"]').click(function(){

var values = [];

$('div[id$="' + tabID + '_SelectedBuyBackFilterDiv"] .children').each(function (){
     $(this).find('option').each(function (){
       var attr = $(this).attr('rel');
       if (typeof attr == 'undefined' ){
         values.push($(this).val());
       }
     });
});
BuyBackGridReload(tabID,values);

}); //End search click

ERROR:

$("table[id$=\"" + tabID + "_BuyBackGrid\"]").setPostData({advertiserID: $("#advertiser_id").text(), CampaignsDdlSelectedValue: $("select[id$=\"CampaignDdl\"] option:selected").val(), startDate: $("input[id$=\"" + tabID + "_FromCalBuyBack_CalendarTbx\"] ").val(), endDate: $("input[id$=\"" + tabID + "_ToCalBuyBack_CalendarTbx\"] ").val(), NoSelectedValue: NoSelectedValues}) is undefined

I also don't want to pass as a querystring for new parameters.

Any suggestion?

Thanks

A

user659469
  • 325
  • 1
  • 7
  • 22

1 Answers1

0

You don't need to use setPostData to set the postData parameter. You can use setGridParam function instead. See here examples.

I suppose if you will use postData parameter which contain functions you will not need to set any postData parameter at all. The url and postData parameters of jqGrid can look like

url:'/Controls/Advertiser/BBControlNew.ascx.ashx",
postData: {
    action: "getBBData"
    advertiserID: function() { return $('#advertiser_id').text(); },
    startDate: function() { return $('input[id$="' + tabID + '_FromCalBuyBack_CalendarTbx"] ').val(); },
    endDate: function() { return $('input[id$="' + tabID + '_ToCalBuyBack_CalendarTbx"] ').val(); },
    advertiserID: function() { return $('#advertiser_id').text(); },
    CampaignsDdlSelectedValue: function() { return $('select[id$="CampaignDdl"] option:selected').val(); },
    startDate: function() { return $('input[id$="'+tabID+'_FromCalBuyBack_CalendarTbx"] ').val(); },
    endDate: function() { return $('input[id$="'+tabID+'_ToCalBuyBack_CalendarTbx"] ').val(); },
    NoSelectedValue: function() { return NoSelectedValues; }
}

The variables tabID and NoSelectedValues must be defined before. On every grid reloading the function from every postData property will be called and you can read the current values from the corresponding controls.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks Oleg. setGridParam works fine. Here is the code. $('table[id$="'+tabID+'_BuyBackGrid"]').jqGrid('setGridParam', {postData:{NoSelectedValue:NoSelectedValues} }).trigger("reloadGrid"); – user659469 Apr 27 '11 at 20:41
  • @user659469: Yes it is work, but you can also set `NoSelectedValues` variable which will be used inside of `postData.NoSelectedValue` function. You don't posted enough code, but I suppose you can calculate the value of `NoSelectedValues` directly inside of `NoSelectedValue: function() {/*here*/}`. Look at [here](http://stackoverflow.com/questions/2928371/how-to-filter-the-jqgrid-data-not-using-the-built-in-search-filter-box/2928819#2928819) for more infos. – Oleg Apr 27 '11 at 20:48
  • @Oleg .As per second approach you have suggested,I don't see any param passing to handler. $('table[id$="'+tabID+'_BuyBackGrid"]').jqGrid({ url :'/Controls/Advertiser/BuyBackControlNew.ascx.ashx?action=getBuyBackData', datatype: 'json',mtype: 'POST',postData: {advertiserID: function() { return $('#advertiser_id').text(); }, startDate: function() { return $('input[id$="'+tabID+'_FromCalBuyBack_CalendarTbx"] ').val(); },endDate: function() { return $('input[id$="'+tabID+'_ToCalBuyBack_CalendarTbx"] ').val(); }} }, I don't see any of these parameters value in firebug. Thanks – user659469 Apr 27 '11 at 21:08
  • @user659469: Which "param"s you mean? Are `advertiserID`, `startDate` and other parameter will not send to the server? Probably you overwrite there in the `serializeGridData` event handle? If the problem is not yet solved you should append your question with more full definition of the jqGrid which you use. – Oleg Apr 27 '11 at 21:21
  • @Oleg: I have edited original question. So now you will figure out how & from where I'm getting NoSelectedValues. When I click "search btn" , I need to pass new parameters to server. Thanks. – user659469 Apr 27 '11 at 21:22
  • @Oleg: please see this link for details question. http://stackoverflow.com/questions/5810885/postdata-not-passing-any-parameters – user659469 Apr 27 '11 at 21:34
  • @user659469: You can define `var values` outside of `.click` handle and use it in both the `.click` handle and the function `NoSelectedValue` inside of `postData`. Moreover if you do want use `setGridParam` with `postData` you should **not overwrite** the old value. Instead of that you should get the current value with `var pd = $('#yourGrid').jqGrid('getGridParam', 'postData')`, then extend the `pd` with `$.extend(pd,{NoSelectedValue:NoSelectedValues});`. The setting of `$('#yourGrid').jqGrid('setGridParam', 'postData', pd)` are mostly not needed because `pd` will be returned as the reference – Oleg Apr 27 '11 at 21:36
  • @Oleg:var pd = $('#yourGrid').jqGrid('getGridParam', 'postData'), then extend the pd with $.extend(pd,{NoSelectedValue:NoSelectedValues}); If I don't use setGridParam as you said "The setting of $('#yourGrid').jqGrid('setGridParam', 'postData', pd) are mostly not needed because pd will be returned as the reference" then how to reload grid withouy setGridParam? – user659469 Apr 27 '11 at 22:00
  • @user659469: I answered to your main problem [here](http://stackoverflow.com/questions/5810885/postdata-not-passing-any-parameters/5811359#5811359). – Oleg Apr 27 '11 at 22:27