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

Heirarchy Child Grid causes error when leveraging logic in ClientTemplate

2 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jean
Top achievements
Rank 1
Jean asked on 13 Sep 2012, 10:54 PM
Hi,

I am currently trying to get the following snippet of code from your Kendo MVC examples project to work. Unfortunately it seems as though having logic in the ClientTemplate on a column (ShipName) in the child grid(in the kendo-templ) causes issues. Any ideas how to get around this?

All help will be massively appreciated.

Jean Hibbert

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.EmployeeViewModel>()
        .Name("Employees")
        .Columns(columns =>
        {
            columns.Bound(e => e.FirstName).Width(140);
            columns.Bound(e => e.LastName).Width(140);
            columns.Bound(e => e.Title).Width(200);
            columns.Bound(e => e.Country).Width(200);
            columns.Bound(e => e.City);
        })
        .ClientDetailTemplateId("employeesTemplate")
        .Pageable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read.Action("HierarchyBinding_Employees""Grid"))
            .PageSize(5)
        )
        .Sortable()
        .Events(events => events.DataBound("dataBound"))
)

<script id="employeesTemplate" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
            .Name("Orders_#=EmployeeID#")
            .Columns(columns =>
            {
                
                columns.Bound(o => o.OrderID).Width(101);
                columns.Bound(o => o.ShipCountry).Width(140);
                columns.Bound(o => o.ShipAddress).Width(200);
                
                columns.Bound(o => o.ShipName)
                .ClientTemplate("#= ShipName? 'XXX' : 'YYY' #")
                .Width(200);
            })
            .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action("HierarchyBinding_Orders""Grid"new { employeeID = "#=EmployeeID#" }))
            )
            .Pageable()
            .Sortable()
            .ToClientTemplate()
    )
</script>
<script>
    function dataBound() {
        this.expandRow(this.tbody.find("tr.k-master-row").first());
    }
</script>

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 14 Sep 2012, 06:23 AM
Hello Jean,

You should escape the # symbol in the templates as what you get here is nested templates(once the child grid and the grid column templates). This is straight forward operation, the template should looks as follow:
.ClientTemplate("\\#= ShipName? 'XXX' : 'YYY' \\#")

More details can be found here: http://docs.kendoui.com/getting-started/framework/templates/overview#template-syntax

Greetings,
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
Jean
Top achievements
Rank 1
answered on 14 Sep 2012, 08:27 PM
Thanks!! That works nicely.
Tags
Grid
Asked by
Jean
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Jean
Top achievements
Rank 1
Share this question
or