开发者

How to Bind a readonly Column for Telerik Grid

开发者 https://www.devze.com 2023-04-06 10:09 出处:网络
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 controll

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(开发者_StackOverflow社区);
        });


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:

    ...
    .Editable(editing =>
    {
        var newItem = new SomeEntity
        {
            Name = "defaultName",
            CreateDate = DateTime.Now,
            OtherProperty = otherValue()
        };
        editing.DefaultDataItem(newItem);
    });


Kendo MVC v 2014.1.528

Put whatever column you want into the grid..

Then in .Datasource, say which columns are editable:

.DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(20)
    .Model(model =>
    {
        model.Id(p => p.Id);
        model.Field(f => f.CreatedDate).Editable(false);
        model.Field(f => f.WhateverColumnYouHaveDefined).Editable(false);
    }
)

Then it will bind, and display, but not be editable.

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消