Hi,
I have a simple master-detail implementation in a hierarchical grid. Everything works as expected if I pass the parent ID in following fashion
@(Html.T4Grid<NTL.Target.BusinessEntities.Customer>("Grid", allColumns,"Customer")
.ClientDetailTemplateId("template")
.HtmlAttributes(new { style = "height:430px;" })
.Events(events => events.DataBound("dataBound"))
)
<script id="template" type="text/kendo-tmpl">
@(Html.Kendo().Grid<NTL.Target.BusinessEntities.Order>()
.Name("Grid_#=CustomerID#")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action("GetList", "Order", new { customerID = "#=CustomerID#" }))
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
</script>
<script>
function dataBound() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
</script>
I intend to abstract binding of the grid completely, as shown above in the code that the data binding has been done in the extension method (T4Grid). Now when I try following it ends up in an error saying 'invalid template'. It throws that error because #=CustomerID# wasn't replaced.
@(Html.T4Grid<NTL.Target.BusinessEntities.Customer>("Grid", allColumns,"Customer")
.ClientDetailTemplateId("template")
.HtmlAttributes(new { style = "height:430px;" })
)
<script id="template" type="text/kendo-tmpl">
@{
name="#=CustomerID#";
gname = "Grid_#=CustomerID#";
}
@(Html.T4Grid<NTL.Target.BusinessEntities.Order>(gname, allColumns, "Order", new { customerID = name }))
.ToClientTemplate()
)
What's the way of getting a field's value (server side) from the data source of the Parent Grid?
Extension Method
public static Kendo.Mvc.UI.Fluent.GridBuilder<T> T4Grid<T>(this HtmlHelper helper, string name, string allColumns, string controllerName, params object[] parameters)
where T : class
{
List<ColumnAttributes> columns = BuildColumns(allColumns);
return helper.Kendo().Grid<T>()
.Name(name)
.Columns(cols =>
{
if (columns != null)
foreach (ColumnAttributes ca in columns)
cols.Bound(ca.Name).Width(ca.Width).Title(ca.Title).Groupable(ca.Groupable);
}
)
.Sortable()
.Pageable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("GetList", "Order",parameters))
);
}