Reputation: 8360
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
Upvotes: 2
Views: 3105
Reputation: 221997
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.
Upvotes: 3