如何为 Telerik Grid 绑定只读列
我有一个 Telerik 网格,其中有一列“创建日期”。我希望该日期可查看,但不可编辑,因此我将其设置为只读。但是,由于它是只读的,因此该属性未绑定在我的控制器中; CreateDate 最终为空。如何使其只读但仍绑定在我的控制器上?
IE
@(Html.Telerik().Grid(Model)
.Name("MainGrid")
.ToolBar(commands => commands.Insert())
.DataKeys(keys => keys.Add(c => c.ID).RouteKey("ID"))
.DataBinding(databinding => databinding
.Server()
.Insert("Insert", "Main")
.Update("Update", "Main")
.Delete("Delete", "Main"))
.Columns(columns =>
{
columns.Bound(o => o.Name).Width(200);
columns.Bound(o => o.CreatedDate).Format("{0:MMM dd, yyyy HH:mm}").ReadOnly().Width(150);
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
});
I have a telerik grid with a column "Created Date". I want this date to be viewable, but not editable, so I set it to ReadOnly. However because it's readonly, the property is not bound in my controller; the CreateDate ends up being null. How can I make it readonly yet still get bound on my controller?
ie
@(Html.Telerik().Grid(Model)
.Name("MainGrid")
.ToolBar(commands => commands.Insert())
.DataKeys(keys => keys.Add(c => c.ID).RouteKey("ID"))
.DataBinding(databinding => databinding
.Server()
.Insert("Insert", "Main")
.Update("Update", "Main")
.Delete("Delete", "Main"))
.Columns(columns =>
{
columns.Bound(o => o.Name).Width(200);
columns.Bound(o => o.CreatedDate).Format("{0:MMM dd, yyyy HH:mm}").ReadOnly().Width(150);
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅.Editable(配置器)。这是一个网格方法,与 .Columns() 等在同一级别上使用。不要以调用 .Columns() 结束,而是尝试添加如下内容:
See .Editable(configurator). This is a grid method, used on the same level as .Columns(), etc. Instead of ending with the call to .Columns(), try something adding something like this:
Kendo MVC v 2014.1.528
将您想要的任何列放入网格中。
然后在.Datasource中,说出哪些列是可编辑的:
然后它将绑定并显示,但不可编辑。
希望有帮助。
Kendo MVC v 2014.1.528
Put whatever column you want into the grid..
Then in .Datasource, say which columns are editable:
Then it will bind, and display, but not be editable.
Hope that helps.