Stuart Hemming
Stuart Hemming

Reputation: 1663

Accessing clientside data in a Kendo Grid Detail Template

Given this UI for MVC example, how do I reference items in the datasource for the detail template in a clientside template?

For example, the Detail Template in the example looks like this....

<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().TabStrip()
            .Name("tabStrip_#=EmployeeID#")
            .SelectedIndex(0)
            .Animation(animation => animation.Open(open => open.Fade(FadeDirection.In)))
            .Items(items =>
            {
                items.Add().Text("Orders").Content(@<text>
                    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
                        .Name("grid_#=EmployeeID#")
                        .Columns(columns =>
                        {
                            columns.Bound(o => o.OrderID).Title("ID").Width(56);
                            columns.Bound(o => o.ShipCountry).Width(110);
                            columns.Bound(o => o.ShipAddress);
                            columns.Bound(o => o.ShipName).Width(190);
                        })
                        .DataSource(dataSource => dataSource
                            .Ajax()
                            .PageSize(5)
                            .Read(read => read.Action("HierarchyBinding_Orders", "Grid", new { employeeID = "#=EmployeeID#" }))
                        )
                        .Pageable()
                        .Sortable()
                        .ToClientTemplate())
                </text>                        
                );
                items.Add().Text("Contact Information").Content(
                    "<div class='employee-details'>" +
                        "<ul>" +
                            "<li><label>Country:</label>#= Country #</li>" +
                            "<li><label>City:</label>#= City #</li>" +
                            "<li><label>Address:</label>#= Address #</li>" +
                            "<li><label>Home Phone:</label>#= HomePhone #</li>" +
                        "</ul>" +
                    "</div>"
                );                
            })
            .ToClientTemplate())
</script>

Lets assume that the column bound to, say, ShipAddress needed to be displayed using a ClientTemplate, writing

columns.Bound(o => o.ShipAddress).ClientTemplate("#=ShipAddress#")

Simply results in "Uncaught ReferenceError: ShipAddress is not defined"

So, How do I get at the Detail Template's datasource items?

Upvotes: 3

Views: 1322

Answers (1)

Stuart Hemming
Stuart Hemming

Reputation: 1663

Apparently, the trick is to delay the processing of the client template inside the detail template by quoting the '#' symbols with '\' like this ...

columns.Bound(o => o.ShipAddress).ClientTemplate("\\#=ShipAddress\\#")

Upvotes: 7

Related Questions