【问题标题】:Why a 404 error for editurl: 'clientData' when deleting a second row from jqGrid?为什么从 jqGrid 删除第二行时 editurl: 'clientData' 出现 404 错误?
【发布时间】:2011-08-01 13:25:45
【问题描述】:

参考用户@Oleg 对jqGrid 本地编辑演示的略微修改版本,位于此处:http://www.dataactive.net/local_editing.htm ...使用下方工具栏中的垃圾箱图标或顶部工具栏上的删除按钮删除一行后,Firebug 中会出现以下错误: "NetworkError: 404 Not Found - http://www.dataactive.net/clientArray"

@Oleg 你能确定为什么会发生这种情况吗?

现在通过删除行解决了这个问题,我观察到的其他事情(记住这是编辑“本地数据”),当新添加的行被删除时,它们似乎并没有消失。考虑一下我试图在另一个脚本中用于生产目的的演示 (@Oleg) 中的 myDelOptions 代码:

myDelOptions = {
    // because I use "local" data I don't want to send the changes
    // to the server so I use "processing:true" setting and delete
    // the row manually in onclickSubmit
    onclickSubmit: function (options, rowid) {
        var grid_id = $.jgrid.jqID(grid[0].id),
            grid_p = grid[0].p,
            newPage = grid_p.page;

        // reset the value of processing option to true to
        // skip the ajax request to 'clientArray'.
        options.processing = true;

        // delete the row
        grid.delRowData(rowid);
        $.jgrid.hideModal("#delmod" + grid_id,
                          { gb: "#gbox_" + grid_id,
                              jqm: options.jqModal, onClose: options.onClose
                          });

        $("#list")[0].refreshIndex();

        setTimeout(function () {
            $("#list").trigger("reloadGrid", [{ current: true}]);
        }, 100);

        calculateTotal();

        if (grid_p.lastpage > 1) {// on the multipage grid reload the grid
            if (grid_p.reccount === 0 && newPage === grid_p.lastpage) {
                // if after deliting there are no rows on the current page
                // which is the last page of the grid
                newPage--; // go to the previous page
            }
            // reload grid to make the row from the next page visable.
            grid.trigger("reloadGrid", [{ page: newPage}]);
        }

        return true;
    },
    processing: true
};

迭代行对象的calculateTotal() 函数仅获取剩余行的列的数值并将它们重新汇总到摘要页脚行,但发生的是迭代行对象网格显示“已删除”的行仍然存在,在数组或其他东西中,因此无法计算新的总数,因为似乎没有任何变化,这些行实际上并没有被删除。我不明白在本地数据的上下文中使用“delRowData”时实际发生了什么,但它似乎只是从可视网格中“删除”该行,但它仍然是行对象的一部分。而且,更奇怪的是,如果添加了另一个新行,则“已删除”的行会重新出现,就像它们在新行之外一样。如您所见,我有refreshIndex[0]trigger(reload),但如果trigger("reload") 存在且refreshIndex[0] 无效,则该行不会删除。任何人都可以解决这个问题吗?需要额外的代码吗?

【问题讨论】:

    标签: jquery jqgrid


    【解决方案1】:

    你是对的。谢谢!该示例的技巧是将processing: true 设置为myDelOptions 的一部分。在第一次删除操作时一切正常,但在第二次调用时,delGridRow 方法的另一部分会将值重置为processing: false

    问题的解决非常简单:只需添加额外的一行

    options.processing = true;
    

    myDelOptionsonclickSubmit 内部。查看修改后的演示here

    【讨论】:

    • @Jerry Of Perth:抱歉,我不明白你的意思。它是 local 网格,用于编辑不应该进行远程调用。你有什么问题?我在演示中看到的唯一内容:var new_id = grid_p.records + 1; 行应替换为var new_id = $.jgrid.randId();。在我第一次编写演示时,jqGrid 中不存在生成 id 的安全方法。后来我建议here新方法,现在在jqgrid中。
    • @Jerry:我再次修改了the demo,并在onclickSubmitLocal方法中包含了$.jgrid.randId()的用法。
    • @Jerry Of Perth:“添加”是对的。我尝试在使用 jqGrid 3.8.2 的代码中使用 $.jgrid.randId(),而 $.jgrid.randId() 仅从 jqGrid 4.0.0 开始存在。我现在必须暂停一下,但我会在接下来的几个小时内发布修改后的代码。
    • @Jerry Of Perth:您可以随时修改您的问题。您可以添加“更新”之类的文本并添加您需要的任何代码。
    • @Jerry Of Perth:看看the demo。它使用 jqGrid 4.1.2、jQuery 1.6.2、jQuery UI 1.8.14。它演示了如何通过上下文菜单、高级搜索和过滤工具栏使用本地表单编辑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 2019-12-06
    • 2017-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多