【问题标题】:How to keep inline add if error is returned on pressing save action button in jqgrid如果在 jqgrid 中按下保存操作按钮时返回错误,如何保持内联添加
【发布时间】:2012-03-05 17:58:02
【问题描述】:

jgGrid 包含工具栏中的内联添加按钮和操作列中的保存操作按钮。 使用远程 json 数据。 如果按下保存操作按钮以终止内联添加并且服务器返回错误, 添加的行从网格中删除,输入的行数据丢失。 我将 restoreAfterError:false 添加到 formatoptions 并内联添加按钮,如下面的代码所示,但如果按下保存操作按钮,这些设置将被忽略。

如果按下保存操作按钮,如何将行保持在内联添加模式下,以便在出错后继续编辑?

colModel: [ {
  name:"_actions",
  formatter:"actions",
  formatoptions:{
    editbutton:true,
    keys:true,
    // this is ignored if action column save button is pressed:
    restoreAfterError:false,
    delbutton:true
    }
} , ...
], 
editurl: '/Grid/Edit',
datatype: "json",

内联添加按钮使用:

$grid.jqGrid('inlineNav', '#grid_toppager', {
    addParams: {
        position: "beforeSelected", 
        rowID: '_empty',
        useDefValues: true,
        addRowParams: {
            keys: true,
            // this is ignored if action column save button is pressed:
            restoreAfterError: false,
        }
    },

    editParams: {
            keys: true,
            // this is ignored if action column save button is pressed:
            restoreAfterError: false,
    },

   add: true,
   edit: false,
   save: true,
   cancel: true
});

【问题讨论】:

    标签: javascript jqgrid


    【解决方案1】:

    我在addParams.addRowParamseditParams 中测试了设置restoreAfterError: false,效果很好。如果出现错误,在我的自定义errorfunc 显示错误消息后,编辑(或新添加的行)将保持在编辑模式。我想您只有在使用 formatter: 'actions' 时才会遇到问题。

    如果您使用formatter: 'actions',则无法直接定义restoreAfterError(至少在当前的jqGrid 3.4.1版本中)。所以我建议你把restoreAfterError的默认值改成false

    $.extend($.jgrid.inlineEdit, {
        restoreAfterError: false
    });
    

    此外,我建议您从addRowParamseditParams 中删除尾随逗号(如此处restoreAfterError: false,})。许多(但不是全部)网络浏览器会忽略尾随逗号,但仍然存在错误。

    【讨论】:

    • 谢谢。使用答案中的代码设置 restoreAfterError 不能解决问题。我在 jqGrid 源代码中的 2 个地方更改了 restoreAfterError ,这解决了这个问题。如何使$.extend($.jgrid.inlineEdit, { restoreAfterError: false }); 工作或找到问题的原因?我正在使用从 git 修补的代码进行 inlineEdit
    • @Andrus:我在the demo project 上测试了我的建议,它使用了original jqGrid 4.3.1。 jqGrid 4.3.1 有一些已知的错误,但所描述的功能可以正常工作。我刚刚在演示中注释了ModifyGridData 的主要代码,所以编辑总是返回错误。如果我在addParams.addRowParamseditParamsinlineNav 属性的一部分中使用restoreAfterError: false,或者如果我使用$.extend($.jgrid.inlineEdit, {restoreAfterError: false});(参见Index.aspx 中的注释部分) - 两者都有效。
    • @Andrus:所以你应该在jqGrid的你修改的代码中遇到一些问题。
    • 我正在使用 Visual Web Developer Express 2010。在尝试运行此解决方案时遇到错误 Could not load file or assembly 'Microsoft.VisualStudio.Web.Runtime。我搜索了整个解决方案,但没有找到对该程序集的任何引用。不知道为什么它需要这个以及如何删除这个引用
    • @Andrus:问题是我最近安装的 Visual Studio 2012 beta。我将在另一台计算机上修复项目中的问题,稍后将更新的演示发布给您。
    猜你喜欢
    • 1970-01-01
    • 2016-01-27
    • 1970-01-01
    • 2013-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    相关资源
    最近更新 更多