I'm new to ASP Core Grid component. I need to build a custom detail template. It has a child grid with its own data source. But it also have some info above the child grid. I started with the 'Grid and Menu' Visual Studio project template and removed unnecessary code. I've attached the UI screenshot and copied the content of Index.cshtml below. I have the following questions:
- The Freight in the detail template is decimal type. How to format it to '0.##'?
- I want to show some information in the detail template that could be part of the master record but cannot be loaded as part of the master record, it's a big performance hit if done that way. So it must be loaded later when the detail expands. I thought I can use the DetailInit event on the master grid but how do I update the UI? Do I re-render the template, do I update the master data record and then refresh the UI somehow?
- I have Refresh button on the detail grid pager. Can I update the entire template (including the Freight and summary info above the detail grid) when this button is clicked? Are there any events I can use to perform (2.) above? Is there a better way?
Any pointers are greatly appreciated.
Thank you!
Index.cshtml:
@{ViewData["Title"] = "Home Page";
}
<div class="row">
<div class="col-12">
@(Html.Kendo().Grid <GridDetail.Models.OrderViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.OrderID).Filterable(false);
columns.Bound(p => p.OrderDate).Format("{0:MM/dd/yyyy}");
columns.Bound(p => p.ShipName);
columns.Bound(p => p.ShipCity);
})
.HtmlAttributes(new { style = "height:550px;" })
.ClientDetailTemplateId("detailTemplate")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("Orders_Read", "Grid"))
)
)
</div>
</div>
<script id="detailTemplate" type="text/html">
<div>Freight: #=Freight#.</div> <!-- How to format the Freight? -->
<div>
Here some information that could come from shared data source.
Or it could be on the master grid record but loaded when the detail expands.
</div>
@(Html.Kendo()
.Grid<GridDetail.Models.OrderDetailViewModel>()
.Name("grid_#=OrderID#")
.Columns(columns =>
{
columns.Bound(c => c.Item);
columns.Bound(c => c.Quantity);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("Order_Details_Read", "Grid", new { orderId = "#=OrderID#" }))
)
// Can the pager refresh be used to trigger update to the entire detailTemplate?
// Is there even that could be used?
.Pageable(pager => pager.Refresh(true))
.ToClientTemplate()
)
</script>