【问题标题】:How does editData work?编辑数据如何工作?
【发布时间】:2013-02-12 14:05:31
【问题描述】:

JqGrid 文档说明了有关 postData 的以下内容:

用于向发布到服务器的数据添加内容的数组

就是这样。因此,我使用 postData 将变量发送到我的 PHP,以便我可以使用 switch case 来调用我想要的函数。

这允许我拥有一个包含项目所有功能的 PHP 页面。我想对editData 做同样的事情,所以我不需要为与项目关联的每个内联编辑功能创建一个 PHP 页面。

但是,editData 似乎没有传递到 PHP 页面。我尝试将 POSTed 变量打印到文件中,但它们是空的。有什么建议吗?

注意:我知道editData 错误,但这应该已由我正在使用的版本 4.4.4 修复

$("#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'
});

【问题讨论】:

  • 您是否在 Firebug/Chrome 之类的东西中看到包含这些变量的传出 POST 操作?它应该像在editData: 参数中传递额外数据一样简单。
  • php 实际上并没有出现在浏览器中,因为我只是通过 jquery 调用 php,所以我认为我无法在 firebug 中看到 POST 变量。但是,我知道 postData 正在被接收(因为它们打印到文件中),而 editData 不是。我因此发送editData:editData:{actions:'grdAdjust'},

标签: php jqgrid


【解决方案1】:

选项editDataform editing 中的作用与主网格中的postData 相同。另一方面,您在问题文本中写了有关“内联编辑”的内容。在这种情况下,您应该改用extraparam 选项(请参阅the documentation)。如果您需要 common 内联编辑选项,那么$.jgrid.inlineEdit 中的使用默认设置可能会对您有所帮助。您没有发布任何代码,我不确定您使用哪种编辑模式和方式,所以我无法提供更多使用示例editDataextraparam 等。

更新:您现在以错误的方式使用extraparamextraparam不是 jqGrid 选项,它是editRow 的选项。正确的用法大概如下:

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

如果您需要action 的后常量值,您可以使用extraparam 的简化形式:如extraparam: {action: 'grdAdjust'}。如果您需要从页面返回某些变量或某些元素的值,这些值将在 editRow 的不同调用之间更改,函数的使用非常有用。

此外,我建议您包含 jqGrid 的 gridview: true 选项并简化您使用的 colModel。如果indexname 具有相同的值,则可以发出它。 width 的默认值已经是 150,所以你也不需要指定 width:150。如果您想在所有或大多数列中使用align:'center',您可以通过在网格中包含cmTemplate: {align:'center'} 选项来更改网格的align 的默认值。因为大多数列有sortable: false,您也可以在cmTemplate 中包含设置。因此,您可以将 colModel 减少为以下内容:

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},

这样的改变不仅简化了代码的阅读,也简化了维护。有关列模板的更多信息,请参阅here

【讨论】:

  • Oleg,我在上面发布了我的代码。它显示了我尝试使用基于我在堆栈中看到的一些代码的 extraparam。在回答您的问题时,我专门尝试进行内联编辑。我知道 extraparam 应该与 saveRow 一起使用,但我不确定在哪里插入。
  • @MattWall: extraparameditRow 的选项,而不是 jqGrid 的选项。你以错误的方式使用它。我将修改我的答案以包含正确用法的示例。
  • @MattWall:我更新了我的答案。不要忘记在所有网格中包含gridview: true
  • 感谢您的帮助!你用关于 cmTemplate 的花絮超越了使命召唤。正在接收编辑参数并将其打印到文件中。
猜你喜欢
  • 2017-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-05
  • 2020-06-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多