2

I'm not able to see any parameters value passing to server in firebug. Here is the code.


//BuyBackGridInit() start

function BuyBackGridInit(tabID){


        $('table[id$="'+tabID+'_BuyBackGrid"]').jqGrid({   
            url :'/Controls/Advertiser/BuyBackControlNew.ascx.ashx?action=getBuyBackData',
            datatype: 'json',
            mtype: 'POST', 
            height:'100%',
            width:'100%',
            colNames: result.colNamesData, 
            colModel: result.colModelData,
            postData: {
              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(); }
            },
            rowNum : 100,
            shrinkToFit :false,
            altRows: true,
            altclass:'altRow',
            autowidth: true,
            multiselect: true,
            gridComplete:function (){
              var recs = parseInt( $('table[id$="'+tabID+'_BuyBackGrid"]').getGridParam("records"),10);
              if (recs == 0){ 
                  $('div[id$="'+tabID+'_NoDataFoundBuyBackdiv"]').show();
                  $('input[id$="AddToCartBtn"]').hide();
                  $('input[id$="BuyBackDownloadBtn"]').hide();
              }
              else {
                  $('div[id$="'+tabID+'_NoDataFoundBuyBackdiv"]').hide();
                  $('input[id$="AddToCartBtn"]').show();
                  $('input[id$="BuyBackDownloadBtn"]').show();
              }
            },
            serializeGridData: function (data){ 
               return $.toJSON(data);   
            }
        });//end of jQuery("#BuyBackGrid").jqGrid()

}//BuyBackGridInit() End

Thanks,

A

Justin Pearce
  • 4,994
  • 2
  • 24
  • 37
user659469
  • 325
  • 1
  • 7
  • 22

1 Answers1

4

You current implementation of serializeGridData just remove all functions parameters from the postData. So you should either extend data parameter inside of serializeGridData instead of the usage of postData. Another way is to modify serializeGridData to the following:

serializeGridData: function (data){
    var propertyName, propertyValue, dataToSend = {};
    for (propertyName in data) {
        if (data.hasOwnProperty(propertyName)) {
            propertyValue = data[propertyName];
            if ($.isFunction(propertyValue)) {
                dataToSend[propertyName] = propertyValue();
            } else {
                dataToSend[propertyName] = propertyValue
            }
        }
   }
   return JSON.stringify(dataToSend);
}

In the code above we enumerate all properties and call all functions explicitly. Moreover I prefer to use JSON.stringify function from json2.js. The function will be native implemented in many web browsers.

See the demo here.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @Oleg : I have replaced my serializeGridData with your piece of code. Now I can see parameters passing to server in firebug. It works fine. But it doesn't change value.It's keep getting old values from controls.I thought postData: part should take care of this. But It didn't. Thanks – user659469 Apr 28 '11 at 14:48
  • @user659469: You wrote "But it doesn't change value. It's keep getting old values from controls". Sorry, but I don't understand which conrols and which values you mean. Moreover you don't posted any time the HTML which you use. – Oleg Apr 28 '11 at 15:04
  • @Oleg : I mean to say control values which I'm setting as parameters inside postData part. postData: { 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(); } }, CampaignsDdlSelectedValue,endDate,startDate all these don't change! – user659469 Apr 28 '11 at 15:07
  • @user659469: Why you mean that jqGrid should **change** contain of any controls which are outside of the grid? – Oleg Apr 28 '11 at 15:10
  • @Oleg: I thought we are discussing about the controls values outside the grid! I see what you saying. But I want to pass new values to server for the controls outside jqgrid. Like date range(textbox), campaignID(dropdown) which are outside the jqgrid. – user659469 Apr 28 '11 at 15:17
  • @user659469: With respect of functions inside of `postData` you archive that **the current value** from the controls outside of jqGrid will be read and send to the server. What I don't understand is: "But it doesn't change value. It's keep getting old values from controls". What changes and when you are wait for? – Oleg Apr 28 '11 at 15:25
  • @Oleg: "But it doesn't change value.It's keep getting old values from controls" - On page load when the call makes to server very first time using this url :'/Controls/Advertiser/BuyBackControlNew.ascx.ashx?action=getBuyBackData', along with that postData: it passes the right values for all controls outisde the jqgrid. But when I click "search btn"(outise the grid), & if I changes date range, dropdown value for campaign, it doesn't read new values from that controls & just passes the previous value.I hope you are getting me now. – user659469 Apr 28 '11 at 15:34
  • @user659469: I found the error in my previous code. See updated code and the demo in the modified text of my answer. – Oleg Apr 28 '11 at 16:48
  • @user659469: You are welcome! I find better to clear all questions. There are really bug in my first suggestion. It's good that the bug was fixed at the end. Best wishes! – Oleg Apr 28 '11 at 18:20
  • @user659469: By the way starting with 15 points of reputation you have **right to vote questions or answers** (not only answers on your question). It is one of the most important rights. The searching engine use voting to find and to sort the questions. [Here](http://stackoverflow.com/faq#howtoask) you can read how to use voting for answers on your questions. Other interesting informations you can find if you look through [FAQs](http://meta.stackexchange.com/questions/7931/faq-for-stack-exchange-sites). – Oleg Apr 28 '11 at 18:28
  • @Oleg: Sure. I'll do that. Thanks. – user659469 Apr 28 '11 at 18:40
  • I want to know which grid is better asp.net datagrid (gridview ) OR Jqgrid ? And why? Thanks, A – user659469 Nov 14 '11 at 17:28