Patrick
asked on 17 Feb 2023, 03:45 PM
| edited on 17 Feb 2023, 03:46 PM
Hello,
I need to implement hierarchical data grid where the relationship between parent-child records is two fields. Can you provide an example of how to establish the relationship in the grid using multiple key fields, please?
Thank you.
Patrick
1 Answer, 1 is accepted
0
Anton Mironov
Telerik team
answered on 22 Feb 2023, 08:17 AM
Hello Patrick,
Thank you for the details provided.
When implementing a hierarchy of Telerik UI Grids, they need only a unique Id(Name). So feel free to use the needed relations in the BackEnd and in the DataBase.
// Child Grid:
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
.Name("grid_#=EmployeeID#") // template expression, to be evaluated in the master context
.Columns(columns =>
{
columns.Bound(o => o.OrderID).Width(110);
columns.Bound(o => o.ShipCountry).Width(150);
columns.Bound(o => o.ShipAddress).ClientTemplate("\\#= ShipAddress \\#"); // escaped template expression, to be evaluated in the child/detail context
columns.Bound(o => o.ShipName).Width(300);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("HierarchyBinding_Orders", "Grid", new { employeeID = "#=EmployeeID#" }))
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
The following demo represents the described implementation needed for a hierarchy of Grids: