jquery - jqGrid:编辑时禁用表单字段

标签 jquery jqgrid editing

我目前正在开发一个网络应用程序,旨在管理自动售货机等。 我决定在这个项目中使用 jQuery、jQuery UI 和 jqGrid,这样我就可以轻松提供出色且高度可定制的用户界面。
不幸的是,jqGrid documentation 已经过时了,并且没有涵盖这个出色插件的所有功能(因为我真的很喜欢它,尽管文档相当糟糕)。

无论如何,我想,背景信息已经足够了。咱们进入正题吧:
我使用 jqGrid 内置的导航栏来添加、编辑和删除网格中的项目。
我已经让它像魅力一样工作,除了一件事:某些字段可能仅在添加新项目时启用(或可见),而不是在编辑模式下启用(它们应该隐藏和/或禁用)。

Example:
The company I'm working for sells vending towers and there are several types (different sizes and stuff) of these towers. When a new tower is added to a location and entered into the system, the type must be set. But the tower doesn't magically change over time, so this field may not be edited later on.

有谁知道这种行为是否可以通过更改一些初始化参数来实现?
也许它是一个未记录的编辑选项 (editoptions) 或表单选项 (formoptions)?
或者也许您有一个简单的解决方案?

我很想听听您的建议/解决方案!
谢谢=)

最佳答案

您可以通过不同的方式实现您的要求。例如,在 beforeShowForm 事件内部,您可以隐藏或显示

jQuery("#list").jqGrid({
    colModel: [
        { name: 'Name', width: 200, editable: true },
   //...

}).jqGrid('navGrid','#pager', { edit: true, add: true, del: false},
          { // edit option
              beforeShowForm: function(form) { $('#tr_Name', form).hide(); }
          },
          { // add option
              beforeShowForm: function(form) { $('#tr_Name', form).show(); }
          });

其中 id“tr_Name”由“tr_”前缀和“Name”(来自 colModel 的列的名称属性)构造而成。

更新:在the answer中并在 another one显示了另一种如何在初始化编辑之前动态更改属性的方法。

更新2:Free jqGrid允许将editable定义为回调函数或“disabled”“hidden”“readonly”。请参阅the wiki article 。它允许更轻松地实现相同的要求。

关于jquery - jqGrid:编辑时禁用表单字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3405029/

相关文章:

javascript - 主干 View 事件在重新渲染后不起作用

Python 音频编辑

CSS 文本编辑

audio - 如何比较两个音频文件并删除两个文件中都存在的数据?

javascript - 我可以使用预设变量放置 json 调用字符串吗?

javascript - mousedown 上的复选框,mouseup 上取消选中

php - HTML5 视频播放转换器

javascript - 在树 jqgrid 中显示 Sparkine

jquery - 获取JQGrid格式化程序: ‘showlink’ to work in MVC

jqGrid置换数组