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

Customizing Column template in Nested Grid

2 Answers 352 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeffrey
Top achievements
Rank 1
Jeffrey asked on 04 Jan 2013, 01:22 AM
For the following code :

<div class="QTFFDetail">
    @(Html.Kendo().Grid(Model.Case.Investigators)
        .Name("Dashboard")
        .Columns(columns =>
        {
   columns.Template(@<text></text>).ClientTemplate("<div>Investigator : #=FirstName# #=LastName# (#=Pernr#) <a href='\\#' style='float:right;' class='openFeedbackForm'>+ Create Feedback Form</a></div>");
   })
        .ClientDetailTemplateId("feedbackFormTemplate")
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model => model.Id(p => p.Pernr))
            .Read(read => read.Action("GetAllInvestigatorsForCase", "CaseSummary"))
        )
    )
</div>

<script id="feedbackFormTemplate" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<Intranet.Data.Review.Info.FeedbackFormInfo>()
        .Name("FeedbackForm_#=Pernr#") 
        .Columns(columns =>
        {
            columns.Template(@<text></text>).HeaderTemplate("<div>#=SubmissionDateString# </div>");
        })
                .ClientDetailTemplateId("reasonTemplate")
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Read(read => read.Action("GetByInvestigator", "FeedbackForm", new { pernr = "#=Pernr#" }))
                )
                .ToClientTemplate()
            )
</script>


... the columns.Template in the feedbackFormTemplate producs a javascript error (JavaScript runtime error: 'SubmissionDateString' is undefined) when I try to expand the row (SubmissionDateString is a property of Intranet.Data.Review.Info.FeedbackFormInfo).
I have seen a ton of nested grid examples, but none that show you how to customize a column in the child grid.

Please advise, thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 04 Jan 2013, 08:48 AM
Hello Jeffrey,

The way nested grid column is defined:
columns.Template(@<text></text>).HeaderTemplate("<div>#=SubmissionDateString# </div>");
the value for "SubmissionDateString" will be searched inside master grid data item Model.Case.Investigators.

If the field is part of nested grid model the template hash("#") must be escaped. Here are few directions:
http://docs.kendoui.com/getting-started/framework/templates/overview#template-syntax
http://www.kendoui.com/forums/mvc/grid/new-client-details-template.aspx

However you should be aware that when header template is evaluated the data item provided is an empty object - { }. That said it will still not contains the field. This field will be available in the column.ClientTemplate which is used for rendering column cells in the row.

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jeffrey
Top achievements
Rank 1
answered on 04 Jan 2013, 10:42 AM
Nikolay,

Thank you so much for your speedy reply, as that did the trick!

Jeff
Tags
Grid
Asked by
Jeffrey
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Jeffrey
Top achievements
Rank 1
Share this question
or