Javascript jQGrid,如何使列在添加对话框中可编辑但在(内联)编辑期间不可编辑
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4307147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQGrid, how to make a column editable in the add dialog but not during (inline) edits
提问by David
I have a jQGrid with a column that I only want to be editable when adding a new row.
我有一个带有列的 jQGrid,我只想在添加新行时对其进行编辑。
I've seen examples of how to do this when edits and adds are both happening in a dialog but is there a way to do this with in-line editing?
我已经看到了在对话框中进行编辑和添加时如何执行此操作的示例,但是有没有办法通过内联编辑来执行此操作?
I've tried using grid.setColProp() in beforeShowForm:, but this doesn't work ( the column remains read only and is not present in the add dialog).
我已经尝试在 beforeShowForm: 中使用 grid.setColProp() ,但这不起作用(该列保持只读状态并且不在添加对话框中)。
Example of dialog based column enable/disable:
http://www.ok-soft-gmbh.com/jqGrid/CustomFormEdit.htm
基于对话框的列启用/禁用示例:http:
//www.ok-soft-gmbh.com/jqGrid/CustomFormEdit.htm
回答by Oleg
Because you use the example from my old answers (thisand this) I feel that I should answer also on your question.
因为您使用了我的旧答案(this和this)中的示例,所以我觉得我也应该回答您的问题。
In the old exampleall fields, which can be modified during Add or Edit dialogs, has property editable:true
. The fields which should be shown only in the Add dialog will be made hidden inside of beforeShowFormevent handle. In the same way we can temporaryswitch some fields to editable:false
before call of the editRow method and reset back to the editable:true
immediately after the call:
在旧示例中,可以在“添加”或“编辑”对话框期间修改的所有字段都具有属性 editable:true
。只应在“添加”对话框中显示的字段将隐藏在beforeShowForm事件句柄中。同理,我们可以临时将一些字段切换到editable:false
editRow方法调用之前,并editable:true
在调用之后立即重置回:
onSelectRow: function(id) {
if (id && id !== lastSel) {
grid.jqGrid('restoreRow',lastSel);
var cm = grid.jqGrid('getColProp','Name');
cm.editable = false;
grid.jqGrid('editRow', id, true, null, null, 'clientArray');
cm.editable = true;
lastSel = id;
}
}
You can see this live here.
你可以在这里看到这个。
UPDATE:Free jqGridallows to define editable
as callback function. See the wiki article. It allows to make the column editable in some rows and holding non-editable for other rows.
更新:免费 jqGrid允许定义editable
为回调函数。请参阅维基文章。它允许使列在某些行中可编辑,而在其他行中不可编辑。