This is a migrated thread and some comments may be shown as answers.

Can the DetailTemplate contain an editable Grid?

1 Answer 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 26 Oct 2012, 01:24 AM
I am working with the following grid and running into an issue with the DetailTemplate:

<%: Html.Kendo().Grid<Thread.Data.Models.Model>()
        .Name("Grid")
        .Columns(columns =>
        {
           columns.Command(command => { command.Edit(); command.Destroy(); }).Width(190).HtmlAttributes(new { style = "text-align:center;" });
           columns.Bound(m => m.ModelID).Hidden();
           columns.Bound(m => m.ModelName).Width(140);
           columns.Bound(m => m.Company).Width(160).ClientTemplate("#= (typeof Company === 'undefined') ? ' ' : Company.CompanyName #").EditorTemplateName("CompanyDropDownList");
            columns.Bound(m => m.DocumentCount).Width(90).ClientTemplate("#= (DocumentCount === null) ? '0' : DocumentCount #");
            columns.Bound(m => m.AlertCount).Width(90).ClientTemplate("#= (AlertCount === null) ? '0' : AlertCount #");
            columns.Bound(m => m.ArticleCount).Width(90).ClientTemplate("#= (ArticleCount === null) ? '0' : ArticleCount #");
           })
        .ClientDetailTemplateId("jobDetailTemplate")
        .ToolBar(toolBar =>
        {
            toolBar.Create();
        })
        .Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
        .HtmlAttributes(new { style = "height: 500px" })
        .Pageable()
        .Sortable()
        .Scrollable()
        .Filterable()
        .Events(events => events.DataBound("dataBound"))
        .DataSource(dataSource => dataSource
            .Ajax()
            .ServerOperation(false)
            .PageSize(2)
            .Events(events => events.Error("error_handler"))
            .Model(model =>
            {
                model.Id(j => j.ModelID);
                model.Field(j => j.ModelID).Editable(false);
                model.Field(j => j.AlertCount).Editable(false);
                model.Field(j => j.ArticleCount).Editable(false);
                model.Field(j => j.DocumentCount).Editable(false);
            })
            .Read(read => read.Action("Model_Read", "Models"))
            .Update(update => update.Action("Model_Save", "Models"))
            .Create(create => create.Action("Model_Save", "Models"))
            .Destroy(destroy => destroy.Action("Model_Destroy", "Models"))
        )
    %>

From there I'm trying to create a DetailTemplate that contains 3 tabs, and in one of the tabs another grid.  So far so good, it loads rows and works fine.  But I want to be able to create/edit/delete the rows in the grid.  When I remove the comments from toolbar, editable, columns.Command in the code below I get this error on the line creating the grid.

 The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'System.String'.

items.Add().Text("Documents").Content(obj => Html.Kendo().Grid<Thread.Data.Models.Article>()

Is this possible to achieve, or am I missing an obvious error?  I saw it in a Telerik ASP.NET demo and wanted to try it here.

   
<script id="jobDetailTemplate" type="text/kendo-tmpl">
       <%: Html.Kendo().TabStrip()
            .Name("TabStrip_#=ModelID#")
            .SelectedIndex(0)
            .Items(items =>
            {
                items.Add().Text("Articles").Content(
                    "<div class='employee-details'>" +
                        "<ul>" +
                            "<li><label>Country:</label>test 1</li>" +
                            "<li><label>City:</label>test 2</li>" +
                            "<li><label>Address:</label>test 3</li>" +
                            "<li><label>Home Phone:</label>test 4</li>" +
                        "</ul>" +
                    "</div>"
                );  
                items.Add().Text("Alerts").Content(
                    "<div class='employee-details'>" +
                        "<ul>" +
                            "<li><label>Country:</label>another test</li>" +
                            "<li><label>City:</label>1</li>" +
                            "<li><label>Address:</label>2</li>" +
                            "<li><label>Home Phone:</label>2</li>" +
                        "</ul>" +
                    "</div>"
                );
                items.Add().Text("Documents").Content(obj => Html.Kendo().Grid<Thread.Data.Models.Article>()
                    .Name("Articles_#ModelID#")
                    //.Toolbar(toolbar => toolbar.Create())
                    //.Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
                    .Columns(columns =>
                    {
                        //columns.Command(command => { command.Edit(); command.Destroy(); }).Width(190).HtmlAttributes(new { style = "text-align:center;" });
                        columns.Bound(a => a.ArticleID).Width(101);
                        columns.Bound(a => a.ArticleName).Width(140);
                        columns.Bound(a => a.CompanyID).Width(200);
                    })
                    .DataSource(dataSource => dataSource
                        .Ajax()
                        .Read(read => read.Action("ModelArticles_Read", "Models", new { modelID = "#=ModelID#" }))
                        .Update(update => update.Action("Article_Save", "Models"))
                        .Create(create => create.Action("Article_Save", "Models"))
                        .Destroy(destroy => destroy.Action("Article_Destroy", "Models"))
                    )
                    .Pageable()
                    .Sortable()
                    .ToClientTemplate()
                );           
            })
            .ToClientTemplate()
            %>
    </script>

Thanks,
Matt

1 Answer, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 26 Oct 2012, 02:08 AM
The answer is yes, error was in column binding.  One of the columns was feeding into an Editor Template incorrectly.
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Share this question
or