如何在编辑模式下使列不可编辑(非只读),在创建模式下使列可编辑

时间:2018-11-27 06:44:12

标签: asp.net-mvc kendo-ui kendo-grid kendo-asp.net-mvc

注意: 我已经检查了以下帖子,它不能解决我的问题

Kendo UI grid - different templates for Edit and Create

我有一个带有下拉列表列的网格,创建新的行模板时只需要编辑此下拉列,执行行编辑功能时就不想编辑此列。

注意:该列在添加新模板时处于下拉状态,在呈现时将是普通文本字段。

我尝试了以下代码

getters setters

但是这样我只能使我的下拉菜单是只读的,但是下拉菜单仍然存在。我不需要这种事情发生。

我想要的是,当用户单击网格行上的“编辑”按钮时,它将不允许用户编辑此特定列,并且此列值应为字符串,不应看起来像只读下拉列表

网格生成代码如下

 function Onedit(e) {
        if (!e.model.isNew()) {
            var model = e.model; //reference to the model that is about the be edited

            var container = e.container; //reference to the editor container

            var categoryDropDownList = container.find("[data-role=dropdownlist]").data("kendoDropDownList"); //find widget element and then get the widget instance
            categoryDropDownList.enable(false);
        }

    }

归档的 @(Html.Kendo().Grid<ViewModel.TemporaryItems>() .Name("AccessGrid") .Columns(columns => { columns.Bound(p => p.Partner).Title("Partner").Width("20%").EditorTemplateName("EditorTemporaryPartnerInfo").EditorViewData(new { TemporaryPartnersList = @Model.TemporaryPartners }); columns.Bound(p => p.UPN).Title("UPN").Width("20%"); columns.Bound(p => p.FullName).Title("Name").Width("20%"); columns.Bound(p => p.Access).Title("Access").Width("20%"); columns.Command(command => { command.Edit(); }).Width("10%"); }) .ToolBar(toolbar => toolbar.Create()) .Editable(editable => editable.Mode(GridEditMode.InLine)) .Sortable() .Scrollable(scrollable => scrollable.Virtual(true).Height(400)) .DataSource(dataSource => dataSource .Ajax() .Sort(a => a.Add(b => b.FullName).Descending()) .PageSize(100) .Model(model => { model.Id(p => p.UPN); model.Field(p => p.FullName).Editable(false); model.Field(p => p.UPN).Editable(false); }) .Events(events => events.Error("error_handler")) .Create(update => update.Action("Action1", "Controller1", new { id = ViewBag.PartnerKey })) .Read(read => read.Action("Action2", "Controller1")) .Update(update => update.Action("Action3", "Controller1", new { id = ViewBag.PartnerKey })) ) .Events(events => events.DataBound("onDataBound")) .Events(e => e.Edit("Onedit")) .Pageable(p => p.Refresh(true).PreviousNext(false).Numeric(false)) ) 是字符串数据类型

我的编辑器模板已添加到下面

Partner

0 个答案:

没有答案
相关问题