如何启用创建,同时禁用Kendo Grid的编辑
是否可以启用只在Kendo网格中插入新记录,但禁用编辑记录?
最好我可以做的是onDataBound删除JavaScript中的“编辑”按钮。 我尝试设置Editable(ed => ed.Enabled(false))
但在运行时出现错误。
@(Html.Kendo().Grid(Model)
.Name("Grid" + guid)
.HtmlAttributes(new { style = "margin:20px" })
.Columns(columns =>
{
columns.Bound(p => p.Id).Hidden(true);
//a few more columns
columns.Command(command =>
{
command.Edit().Text(Resources.KendoEdit).UpdateText(Resources.KendoUpdateText).CancelText(Resources.KendoCancelText);
command.Destroy().Text(Resources.KendoDestroy);
}).Title(Resources.KendoCommands).Width(180);
})
.ToolBar(toolbar => toolbar.Create().Text(Resources.KendoToolbarCreate))
.Editable(editable => editable
//.Enabled(false)
.Mode(GridEditMode.InLine)
.DisplayDeleteConfirmation(false)
)
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Events(events => events.Sync("sync").Error("error"))
.Model(mod => mod
.Id(p => p.Id)
)
.Model(mod => mod
.Field(p => p.OldRoleId).Editable(false)
)
.Read(read => read.Action("ChangeRole_Read", "ChangeRole"))
.Create(update => update.Action("ChangeRole_Create", "ChangeRole"))
.Update(update => update.Action("ChangeRole_Update", "ChangeRole"))
.Destroy(update => update.Action("ChangeRole_Destroy", "ChangeRole"))
)
.Sortable()
.Filterable(filterable => filterable
.Extra(true)
.Operators(operators => operators
.ForString(str => str.Clear()
.StartsWith(Resources.KendoFilterStartsWith)
.IsEqualTo(Resources.KendoFilterIsEqualTo)
.IsNotEqualTo(Resources.KendoFilterIsNotEqualTo)
.Contains(Resources.KendoFilterContains)
.DoesNotContain(Resources.KendoFilterDoesNotContain)
.EndsWith(Resources.KendoFilterEndsWith)
)
)
.Messages(mess => mess
.Info(Resources.KendoFilterMsgInfo)
.And(Resources.KendoFilterMsgAnd)
.Or(Resources.KendoFilterMsgOr)
.Filter(Resources.KendoFilterMsgFilter)
.Clear(Resources.KendoFilterMsgClear)
)
)
.Scrollable()
.Pageable(pg => pg
.Refresh(true)
.Messages(ms => ms
.First(Resources.KendoPageableFirst)
.Last(Resources.KendoPageableLast)
.Next(Resources.KendoPageableNext)
.Previous(Resources.KendoPageablePrevious)
.Empty(Resources.KendoPageableEmpty)
.Display(Resources.KendoPageableDisplay)
)
)
.Events(ev => ev
.Edit("edit")
.Save("save")
.DataBound("dataBound")
)
)
唯一的方法是将Edit按钮的可见性设置为None:
<style>
#yourgridid .k-grid-edit
{
display: none;
}
</style>
如果没有你用来初始化网格的代码很难回答,但是我要去尝试一下。 如果我没有记错,你必须明确告诉Kendo添加一个带有编辑/删除按钮的列,如下所示:
.Columns(columns =>
{
columns.Bound(m => m.Whatever);
columns.Command(command =>
{
command.Edit();
command.Destroy();
});
})
所以如果你的列定义中有这样或那样的东西,删除它将摆脱编辑/删除,但保持网格顶部栏中的添加按钮。
如果这不是您编辑/删除按钮的设置方式,我很乐意在发布网格代码时修改我的答案。
此修复程序位于以下注释行中:
.Columns(cols =>
{
cols.Bound(c => c.name).Width(300);
cols.Bound(c => c.dateBuilt);
cols.Command(cmd =>
{
cmd.Select();
//cmd.Edit();//This is the part to comment out if u want to disable edit
cmd.Destroy();
});
})
链接地址: http://www.djcxy.com/p/12141.html
上一篇: How to enable create, while also disabling edit for a Kendo Grid