【问题标题】:jqGrid edit record form emptyjqGrid 编辑记录表单为空
【发布时间】:2023-03-28 18:28:01
【问题描述】:

我已经实现了一个 jqGrid,但是当我尝试使用内置的表单编辑功能时,会弹出一个空表单。

对于我设置的每一列 editable:true 除了表的主键,一个自动递增的 id。我究竟做错了什么?我需要有一个有效的editurl,而不是clientArray吗?下面是 jqGrid 的实现:

$.ajax({
    type: "GET",
    url: colUrl,
    datatype: "json",
    success: function(result){
        result = jQuery.parseJSON( result )
        var colN = result.colNames;
        var colM = result.colModelList;
        $("#jqTable").jqGrid({
            url:dataUrl,
            datatype: 'xml',
            mtype: 'GET',
            colNames:colN,
            colModel:colM,
            shrinkToFit: false,
            caption: db + "." + table,
            pager: '#jqPager',
            rowNum:10,
            rowList:[10,20,30],
            sortname: 'dbid',
            editurl: 'clientArray',
            sortorder: 'asc',
            viewrecords: true,
            width: 1000,
            height: 400
          });
        $("#jqTable").jqGrid('navGrid', '#jqPager',
            {edit:true, add:false, del:false, search:true, view:false}, //options
            {}, // edit options
            {}, // add options
            {}, // del options
            {multipleSearch:true,
             sopt : ['eq',//equals
                 'ne',//not equals
                 'lt',//less than
                 'le',//less than or equal
                 'gt',//greater than
                 'ge',//greater than or equal
                 'bw',//begins with
                 'bn',//does not begin with
                 'in',//in
                 'ni',//not in
                 'ew',//ends with
                 'en',//does not end with
                 'cn',//contains
                 'nc']//does not contain
            }, // search options
            {} //view options
        ); 
    },
    error: function(x,e){
        alert(x.readyState + " " + x.status + " " + e.msg);
    }
});

这里是示例 colModel 和 ColName 字符串:

"colModelList": [{"name":"dbid","index":"dbid","editable":"false"},{"name":"description","index":"description","editable":"true"},{"name":"file_name","index":"file_name","editable":"true"}],"colNames": ["dbid","description","file_name"]

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    我想原因是因为您使用"editable": "true""editable": "false" 而不是"editable": true"editable": false

    此外,您尝试使用form editing 进行本地数据编辑。当前的 jqGrid 实现仅支持 cell editinginline editing 的本地数据编辑。如果您确实需要使用form editing 来编辑本地数据,您可以在the answer 中找到my demo。代码会比较长,但是可以实现。

    【讨论】:

    • 将 "editable":"true" 更改为 "editable":true 并填充表单。太棒了!
    • @Andrea:在www.json.org上你可以发现boolean数据类型应该不用双引号进行编码。
    • 有时这是最简单的事情......我正在重写我的应用程序的控制流,并将所有可编辑项目的默认设置为false,但无法弄清楚发生了什么。找到我的错误并修复它,谢谢:)
    • 哦,我在这个问题上花了 4 个小时 :( 感谢 Oleg!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多