2

This is my jqGrid handler.

var myEditParams = {
    keys: true,
    extraparam: {
        ajax: function () {
            alert("in myEditParams:extraparam");
            return "1";
        }
    }
};
var lastsel;
jQuery("#list2").jqGrid({
        data: data,
        height: 250,
        emptyDataText: "No Records Found",
        width: $('#mainwrapper').width(),
        datatype: "local",        
        colNames:['Table Description','Display Table name'],
        colModel:[
            { name:'table_desc', index:'table_desc', sortable: false, align: 'left', editable: true, edittype: 'text', editoptions:{ size:40 }, formatoptions:{
                keys: true,
                editOptions: myEditParams
            } },
            { name:'display_table_name',index:'display_table_name', sortable: false }
        ],
        loadComplete: function(){
            $('.ui-jqgrid-htable').css('width',$('#mainwrapper').width()+'px');
             if ($('#list2').getGridParam('records') == 0){ // are there any records?
                DisplayEmptyText(true);
             }else{
                DisplayEmptyText(false); 
             }                    
        },
        rowNum:10,
        rowList:[10,20,30],
        pager: '#pager2',
        sortname: 'id',
        viewrecords: true,
        sortorder: "desc",
        caption:"Changelog Tables",
        postData: { ajax: "1" },
        onSelectRow: function(id){
            if(id && id!==lastsel){
                jQuery('#list2').jqGrid('restoreRow',lastsel);
                jQuery('#list2').jqGrid('editRow',id,true);
                $('#list2').jqGrid('setGridParam',id,{ ajax:"1" }); //wanted to set some custom params here.
                lastsel=id;
            }
        },
        editurl: "changeLog.php"
    });

I want to send one extra param as ajax=1, when I do some in-place edit operation. I have tried every way. But nothing seems to work. I am almost frustrated.

I tried this:

$("#list2").jqGrid('setGridParam',{postData:{ajax:'1'}});

Didn't work. I also tried setting postData param as you can see in the handler. That too is not working. What is going wrong here? Please help me with this

Shades88
  • 7,934
  • 22
  • 88
  • 130

1 Answers1

3

The method editRow supports extraparam. So you can rewrite onSelectRow so:

onSelectRow: function (id) {
    var $myGrid = $(this); // it's better as jQuery('#list2')
    if (id && id !== lastsel) {
        $myGrid.jqGrid('restoreRow', lastsel);
        $myGrid.jqGrid('editRow', id, {
            keys: true,
            extraparam: { ajax: "1" }
        });
        lastsel = id;
    }
}

By the way you can use methods (functions) instead of properties in the extraparam. It can be helfull in the following case. The values like extraparam: { ajax: $("#myControl").val() } will be calculated at the moment of the call the editRow function. If you would be use extraparam: { ajax: function () { return $("#myControl").val(); } } then the value of ajax parameter will be evaluated at the moment of saving of the value. At the moment the $("#myControl").val() can have another value.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • even this didn't work. I am totally confused. How none of the solutions are working? – Shades88 Apr 10 '12 at 05:33
  • @Shades88: Look at [the demo](http://www.ok-soft-gmbh.com/jqGrid/SendDataFromInlineNav1.htm) from [the answer]. Click on "Add" button and try to save something. You will see that function from the `exraparam` are called. Look at [another demo](http://www.ok-soft-gmbh.com/jqGrid/inlineDataAsFunction.htm) from [the answer](http://stackoverflow.com/a/8512693/315935). It works too. After all you can compare the demos with your code. – Oleg Apr 10 '12 at 06:41
  • ok please check updated code. I made the changes by seeing your demo, but still not working – Shades88 Apr 10 '12 at 07:11
  • @Shades88: Sorry, but you don't use any from my suggestions! The code in `onSelectRow` still use `setGridParam` which do nothing helpful and you use `formatoptions` of `formatter: 'actions'`, but not use the `formatter` itself. You should just replace `onSelectRow` with the code which I posted. – Oleg Apr 10 '12 at 09:46
  • Hi, yes I did not use that code of your's. I saw it and it seemed like you just used an object of jqGrid to call methods, instead of jqGrid('#list2'). So I ignored it and tried next code you gave. But that one worked like magic. Thanks a million and sorry for my stupidity :) – Shades88 Apr 10 '12 at 10:56