9

我有一个关于如何在 kendo UI 中实现 readonly on edit 的问题。详细解释见下文

我有以下字段:

名字(创建时可编辑)(编辑时可编辑)
姓氏(创建时可编辑)(编辑时可编辑)
用户名(创建时可编辑)(编辑时只读)
电子邮件(创建时可编辑)(编辑时可编辑)
电话号码(创建时可编辑) (编辑时可编辑)
PreWin2KUserName(创建时不可编辑)(编辑时只读)

使用 Kendo UI 网格参考链接 http: //demos.kendoui.c​​om/web/grid/editing-inline.html

加上这个来实现 http://www.kendoui.c​​om/forums/ui/grid/ making-column-as-readonly-on-update-and-editable-on-insert-in-grid.aspx

4

1 回答 1

9

您可以使用网格的编辑事件。如果模型不是新模型,即用户正在编辑(而不是创建)记录,则您将只读属性附加到所需的输入元素。

$('#yourGrid').kendoGrid({
     // ...
     edit: function(e) {
         if (!e.model.isNew()){
             // make sure the UserName id selector is correct in your code
             // (it should be, for a regular text input)
             $('#UserName').attr('readonly', 'readonly');
         }
     }
})
于 2012-11-15T23:45:17.797 回答