jqGrid:编辑时禁用表单字段 [英] jqGrid: Disable form fields when editing

查看:244
本文介绍了jqGrid:编辑时禁用表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个用于管理自动售货机等的Web应用程序. 我决定在该项目中使用jQuery,jQuery UI和jqGrid,因此我可以轻松提供一个功能强大且可高度自定义的用户界面.
不幸的是, jqGrid文档 已经过时了,不能涵盖这个出色的插件的所有功能(因为我非常喜欢它,即使文档很差).

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).

无论如何,我想有足够的背景信息.让我们指出一点:
我使用jqGrid内置的导航栏从网格中添加,编辑和删除项目.
除了一件事情外,我的工作就像一种魅力:一些字段仅在添加新项目时才启用(或可见),而在编辑模式下则应启用(应将其隐藏和/或禁用).

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.

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

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 =)

推荐答案

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

You can implement your requirements in different ways. For example, inside of beforeShowForm event you can hide or show the

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中列的name属性)构成的.

where 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.

更新2 :免费jqGrid 允许定义作为回调函数或"disabled""hidden""readonly".参见 Wiki文章.这样可以更轻松地实现相同的要求.

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.

这篇关于jqGrid:编辑时禁用表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆