Grid CRUD operations loading data form DataTable object

2 posts, 1 answers
  1. Answer
    Alberto
    Alberto avatar
    4 posts
    Member since:
    Nov 2012

    Posted 14 Mar 2013 Link to this post

    I'm having problems to add/edit/delete rows on a grid loaded from DataTable

    I have something like the following code:
    @(Html.Kendo().Grid<object>()
            .HtmlAttributes(new { style = "height: 80%;" })
            .Name("grid-records")
            .Columns(columns =>
            {
                columns.LoadSettings(Model.GridColumns);
                foreach (GridColumnSettings item in Model.GridColumns)
                {
                    ModelFieldDescriptor modelField = new ModelFieldDescriptor();
                    modelField.Member = item.Member;
                    modelField.MemberType = item.MemberType;
                    modelField.DefaultValue = null;
                    modelField.IsEditable = true;              
                    columns.Container.DataSource.Schema.Model.Fields.Add(modelField);
                }
                //columns.Command(command => { command.Edit(); command.Destroy(); }).HtmlAttributes(new { style = "float:right;" });
                columns.Command(command => command.Custom("ViewDetails"));
            })
            .Groupable()
            .Pageable()
            .Sortable()
            .Scrollable()
            .Filterable(Web.Helpers.KendoI18n.SetGridFilterableSettings)
            //.Editable(editable => editable.Mode(GridEditMode.InLine))
            .DataSource(dataSource => dataSource
                .Ajax()
                .Events(events => events.Error("error_handler"))
                .Read(read => read.Action("GetRecords", "Records", new { currentTableId = Model.CurrentTableId }))
                //.Update(update => update.Action("UpdateRecordFromGrid", "Design"))
                //.Destroy(destroy => destroy.Action("DeleteRecordFromGrid", "Design"))
            )
        )
    In the above code if I uncomment the "commented lines" .. the exception is:

    "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions." 

    Could you tell me what I should do to enable CRUD operations on this case?

    Thanks
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 18 Mar 2013 Link to this post

    Hello Alberto,

    The question is already discussed in this forum thread:


    http://www.kendoui.com/forums/mvc/grid/problem-with-crud-operation-with-data-table-as-model.aspx

    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top