jqGrid:编辑时禁用表单字段
我目前正在开发一个网络应用程序,旨在管理自动售货机等。 我决定在这个项目中使用 jQuery、jQuery UI 和 jqGrid,这样我就可以轻松提供出色且高度可定制的用户界面。
不幸的是,jqGrid 文档 已经非常过时了,而且没有涵盖这个伟大插件的所有功能(因为我真的很喜欢它,尽管文档相当糟糕)。
不管怎样,我想,足够的背景信息了。让我们进入正题:
我使用 jqGrid 内置的导航栏来添加、编辑和删除网格中的项目。
我已经让它像魅力一样工作,除了一件事:某些字段可能仅在添加新项目时启用(或可见),而不是在编辑模式下启用(它们应该隐藏和/或禁用)。
示例:
我工作的公司销售自动售货机和 有几种类型(不同 这些塔的尺寸和内容)。什么时候 一个新的塔楼被添加到一个位置并且 输入系统,类型 必须设置。但塔没有 随着时间的推移神奇地改变,所以这 以后可能无法编辑该字段。
有谁知道这种行为是否可以通过更改一些初始化参数来实现?
也许它是一个未记录的编辑选项 (editoptions) 或表单选项 (formoptions)?
或者也许您对此有一个简单的解决方案?
我很想听听您的建议/解决方案!
谢谢=)
I'm currently developing a web application designed for the administration of vending machines and such.
I decided to use jQuery, jQuery UI and jqGrid for this project, so I can easily provide a great and highly customizable user interface.
Unfortunately, the jqGrid documentation is pretty outdated and doesn't cover all the features of this great plug-in (cause I do really like it, even though the documentation is rather poor).
Anyway, enough background information, I suppose. Let's get to the point:
I use the navbar which is built-in to jqGrid to Add, Edit and Delete items from the grid.
I've got this working like a charm, except for one thing: some fields may only be enabled (or visible) when adding a new item and not when in editing-mode (they should be hidden and/or disabled).
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.
Does anyone know if this behavior can be accomplished by changing some initialization parameters?
Perhaps it's an undocumented edit-option (editoptions) or form-option (formoptions)?
Or maybe you've got a simple solution for this?
I'd love to hear your suggestion / solutions!
Thanks =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以通过不同的方式实现您的要求。例如,在
beforeShowForm
事件内部,您可以隐藏或显示id“tr_Name” 由“tr_”前缀和“Name”(来自
colModel 的列的名称属性)构造的位置
。更新:在答案和另一个显示了如何在初始化编辑之前动态更改属性的另一种方式。
更新2:免费jqGrid允许定义
可编辑< /code> 作为回调函数或作为
“disabled”
、“hidden”
或“readonly”
。请参阅wiki 文章。它允许更容易地实现相同的要求。You can implement your requirements in different ways. For example, inside of
beforeShowForm
event you can hide or show thewhere the id "tr_Name" is constructed from "tr_" prefix and "Name" - the name property of the column from the
colModel
.UPDATED: In the answer and in another one are shown one more way how the properties can be changed dynamically immediately before the editing will be initialized.
UPDATED 2: Free jqGrid allows to define
editable
as callback function or as"disabled"
,"hidden"
or"readonly"
. See the wiki article. It allows to implement the same requirements more easy.为了使字段可编辑或不可编辑,这就是我在搜索答案一段时间后结束的编码(禁用行内编辑编辑,但允许“添加”编辑)并且没有找到我需要的答案:
To make the field editable or not, this is what I wound up coding after searching for an answer for a while (to disable editing on in-row edit, but allow it on 'Add') and not finding the answer I needed:
这是一个示例:
http://www.ok-soft-gmbh.com/ jqGrid/CustomFormEdit.htm
Here is an example:
http://www.ok-soft-gmbh.com/jqGrid/CustomFormEdit.htm
可见但不可编辑:
Visible but not editable:
这将与免费的 jqgrid 一起使用,简单明了:
这个特定的示例将只允许以“添加”形式进行编辑:
This will work with the free jqgrid, plain and simple:
This particular example will allow edit only in the "add" form: