Hi,
I am trying to build a grid that has a detail template displaying child records. One of the columns in the grid (both the main grid and sub-grid) should display a dropdown menu. This is all mostly straightforward but I have a couple of issues/questions.
1. The properties of the child objects do not seem to be available within the context of the detail template. How can I access those properties?
2. I cannot seem to figure out how to add the dropdown menu in the grid column. I've tried to apply examples from the demos but keep getting errors like "Invalid Template" when attempting to use a client template or "Cannot convert lambda expression" when I try to use a foreach loop to add submenu items.
Product: Telerik MVC UI
Version: 2016.2.714
Please take a look at the attached sample solution and point me in the right direction. (I could not add the Content and Scripts folders as they cause me to exceed the 2MB upload limit; however those folder are out of the box Telerik MVC UI scaffolded so I hope you can add them). Also see the Razor View code below.
@{ViewBag.Title = "Home Page";
}
<div class="container-fluid">
<div class="row">
<div class="col-xs-18 col-md-12">
@(Html.Kendo().Grid<TelerikMvcApp1.Models.Shop>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(e => e.ShopId).Width(110);
columns.Bound(e => e.ShopName);
columns.Template(@<text></text>).ClientTemplate(
Html.Kendo().Menu()
.Name("menu_#=ShopId#")
.Items(menu =>
{
menu.Add().Text("Pay Affiliates").Items(nested =>
{
// How does one loop through the affiliates here?
nested.Add()
.Text("[How to get affiliate name here]?");
// .Action("ActionName", "ControllerName", new { ShopId = "#=ShopId#", AffiliateId = "#=AffiliateId#" });
});
})
.ToClientTemplate().ToHtmlString()
);
})
.Sortable()
.Pageable()
.Scrollable()
.ClientDetailTemplateId("affiliates-template")
.HtmlAttributes(new { style = "height:600px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(6)
.Read(read => read.Action("Shops_Read", "Grid"))
)
.Events(events => events.DataBound("dataBound"))
)
</div>
</div>
</div>
<script id="affiliates-template" type="text/kendo-tmpl">
@(Html.Kendo().Grid<TelerikMvcApp1.Models.Affiliate>()
.Name("grid_#=ShopId#") // template expression, to be evaluated in the master context
.Columns(columns =>
{
columns.Bound(o => o.AffiliateId).Width(110).ClientTemplate(" \\#= AffiliateId \\#"); ;
columns.Bound(o => o.AffiliateName).ClientTemplate(" \\#= AffiliateName \\# promotes \\#= ShopName \\#");
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("Affiliates_Read", "Grid", new { ShopId = "#=ShopId#" }))
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
</script>
<script>
function dataBound() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
</script>