1

Why PostData value is never sent to the server? If i user a fixwed value postData: {test: "3"} it works but when using functions nothing is passed to the server..... Firebug does not reveal any trace of the test variable

$("#tblgrid").jqGrid({
            datatype: 'json',
            ajaxGridOptions: { contentType: "application/json" },
            ajaxRowOptions: { contentType: "application/json", type: "POST" }, //row inline editing
            serializeGridData: function(postData) { return JSON.stringify(postData); },
            jsonReader: {
                repeatitems: false,
                id: "0",
                cell: "",
                root: function(obj) { return obj.d.rows; },
                page: function(obj) { return obj.d.page; },
                total: function(obj) { return obj.d.total; },
                records: function(obj) { return obj.d.records; }
            },
            url: 'orthofixServices.asmx/GetProductList',
            postData: { test: function() { return $("#tid").val(); } },
            datatype: 'json',
            colNames: ['id', 'Product Description', 'Commission Rate'],
            colModel: [
            { name: 'id', width: 50 },
            { name: 'description', index: 'desc', width: 380, editable: true },
            { name: 'commissionrate', index: 'com', width: 120, editable: true, unformat: percentUnFormatter, formatter: percentFormatter, editrules: { number: true} }
            ],
            serializeRowData: function(data) {

                var params = new Object();
                params.id = 0;
                params.prdid = 4;
                params.description = data.description;
                params.commissionrate = data.commissionrate;
                var result = JSON.stringify({ 'passformvalue': params, 'oper': data.oper, 'id': data.id });
                return result;
            },
            mtype: "POST",

            rowNum: 4,
            width: 500,
            height: 80,
            pager: '#pager',
            editurl: "orthofixServices.asmx/ModifyProductList"
        });
        $("#tblgrid").jqGrid('navGrid', '#pager', { add: false, edit: false, del: true }, {
        //edit options

    }, {
    //add options     

}, {
//delete options

});

Manuel Valle
  • 297
  • 8
  • 18

2 Answers2

0

The postData field represents data to be sent to the server:

This array is passed directly to the url. This is associative array and can be used this way: {name1:value1...}.

The problem with your code is that you are trying to pass a function (code) to the server. Instead you need to pass the data directly:

postData: { test: $("#tid").val() }
Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
  • 1
    I was trying to do what was explained here: http://stackoverflow.com/questions/2826478/jqgrid-not-updating-data-on-reload . So postData does seems to accept a function that will be dynamically updated on every reload of the grid – Manuel Valle May 16 '12 at 18:51
0

You need to actually execute the functions that you have set your postData to.

Add this into your serializeRowData:

                   for (propertyName in data) {
                        if (data.hasOwnProperty(propertyName)) {
                            propertyValue = data[propertyName];
                            if ($.isFunction(propertyValue)) {
                                dataToSend[propertyName] = propertyValue();
                            } else {
                                dataToSend[propertyName] = propertyValue;
                            }
                        }
                    }
Brandon
  • 983
  • 6
  • 15