Reputation: 99
I have a one-to-many relationship between person and address and I would like to display all the addresses in the grid detail. I know how to do this in a column, but it will look ugly.
@(Html.Kendo().Grid(Model)
.Name("Test")
.Columns(c =>
{
c.Bound(p => p.FirstName);
c.Bound(p => p.LastName);
c.Bound(p => p.Addresses).Template(
@<text>
<ul>
@foreach (var a in @item.Addresses)
{
<li>@a.City</li>
<li>@a.Street</li>
}
</ul>
</text>);
})
.Pageable()
.Sortable()
.Filterable()
.Groupable()
.ClientDetailTemplateId("template")
.HtmlAttributes(new { style = "min-height:200px;" })
)
I know I'm supposed to use a detail template, but I don't know how to access the correct person in the script.
<script id="template" type="text/x-kendo-template">This
is where I need to iterate over the addresses
</script>
What's the best way of approaching it?
Upvotes: 0
Views: 1099
Reputation: 1703
Current template is driven each grid row for Addresses column. You can iterate Addresses list and include address information e.g. html list.
<script id="template" type="text/x-kendo-template">
<ul>
# for (var i = 0; i < data.Addresses.length; i++) { #
<li>#=data.Addresses[i].City#</li>
# } #
</ul>
</script>
Upvotes: 1