How does editData work?

2019-09-08 18:01发布

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'
});

标签: php jqgrid
1条回答
Melony?
2楼-- · 2019-09-08 18:40

The option editData play the same role in form editing as postData in the main grid. On the other side you wrote about "inline editing" in the text of your question. In the case you should use extraparam 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 usage editData, extraparam etc.

UPDATED: You use extraparam in a wrong way now. extraparam is not jqGrid option, it's option of editRow. Correct usage could be about the following:

onSelectRow: function (id) {
    if (id && id !== lastSel){
        $(this).jqGrid("restoreRow", lastSel);
        $(this).jqGrid("editRow", id, {
            keys: true,
            extraparam: {
                action: function () {
                    return 'grdAdjust';
                }
            }
        });
        lastSel = id;
    }
}

If you need post constant value of action you can use simplified form of extraparam: like extraparam: {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 of editRow.

Additionally I would recommend you to include gridview: true option of jqGrid and to simplify colModel which you use. If index has the same value as name you can emit it. The default value of width is already 150, so you don't need specify width:150 too. If you want use align:'center' in all or in the most columns you can change the default value of align for the grid by including cmTemplate: {align:'center'} option in the grid. Because the most column has sortable: false you can include the setting in the cmTemplate too. As the result you can reduce colModel to the following:

colModel: [
    {name: 'label', editable: true},
    {name: 'cntrct_id', sortable: true},
    {name: 'amount', editable: true},
    {name: 'type_cd', editable: true},
    {name: 'rec_cd'},
    {name: 'db_seq'},
],
cmTemplate: {align: 'center', sortable: false},

Such changes simplify the code not only for reading, but for maintain too. See here more information about column templates.

查看更多
登录 后发表回答