JqGrid documentation states the following regarding postData:
an array used to add content to the data posted to the server
And that's it. So, I'm using postData to send a variable to my PHP so that I can use a switch case to call the function I want.
This allows me to have a single PHP page containing all the functions for my project. I want to do the same thing with editData
so I don't need a PHP page for every inline editing function associated with the project.
However, editData
doesn't seem to be passing to the PHP page. I tried printing the POSTed variables to a file and they were empty. Suggestions?
Note: I am aware of the editData
bug, but this should have been fixed by version 4.4.4 which is the one I'm using
$("#list").jqGrid({
url:'functions.php',
datatype:'xml',
mtype:'POST',
postData: {
action:'popGrid',
sqlCount:sqlCount,
sqlSelect:sqlSelect,
sqlSelect2:sqlSelect2,
label1:label1,
label2:label2,
},
colNames:['Label','Account_Num','Amount', 'Type Code', 'Record Code', 'Sequence'],
colModel :[
{name:'label', index:'label', width:150, align:'center', sortable:false, editable:true},
{name:'cntrct_id', index:'cntrct_id', width:150, align:'center', sortable:true},
{name:'amount', index:'amount', width:150, align:'center', sortable:false, editable:true},
{name:'type_cd', index:'type_cd', width:150, align:'center', sortable:false, editable:true},
{name:'rec_cd', index:'rec_cd', width:150, align:'center', sortable:false},
{name:'db_seq', index:'db_seq', width:150, align:'center', sortable:false},
],
editurl: 'functions.php',
extraparam: { action: function(){ return 'grdAdjust'; } },
onSelectRow: function(id) {
if(id && id!==lastSel) {
jQuery('#list').restoreRow(lastSel);
jQuery('#list').editRow(id,true);
lastSel=id;
}
},
pager: '#pager',
rowNum:100,
rowList:[100,200,300,400,500,600,700,800,900,1000],
sortname: 'cntrct_id',
sortorder: 'desc',
viewrecords: true,
caption: 'Adjustments'
});
The option
editData
play the same role in form editing aspostData
in the main grid. On the other side you wrote about "inline editing" in the text of your question. In the case you should useextraparam
option instead (see the documentation). If you need to have common options of inline editing then probably the usage defalut settings in$.jgrid.inlineEdit
could be helpful for you. You don't posted any code and I am not sure which editing mode and in which way you use, so I can't include more examples of usageeditData
,extraparam
etc.UPDATED: You use
extraparam
in a wrong way now.extraparam
is not jqGrid option, it's option ofeditRow
. Correct usage could be about the following:If you need post constant value of
action
you can use simplified form ofextraparam
: likeextraparam: {action: 'grdAdjust'}
. The usage of functions is really helpful if you need return the value of some variable or some element from the page which will be changed between different calls ofeditRow
.Additionally I would recommend you to include
gridview: true
option of jqGrid and to simplifycolModel
which you use. Ifindex
has the same value asname
you can emit it. The default value ofwidth
is already 150, so you don't need specifywidth:150
too. If you want usealign:'center'
in all or in the most columns you can change the default value ofalign
for the grid by includingcmTemplate: {align:'center'}
option in the grid. Because the most column hassortable: false
you can include the setting in thecmTemplate
too. As the result you can reducecolModel
to the following:Such changes simplify the code not only for reading, but for maintain too. See here more information about column templates.