hello, what is the general pattern to include a grid inside another Grid's DetailTemplate? I have a heriarchical collections I need to populate. I don't see other way than declaring a script inside the template's script tag, but that is invalid html.
1 Answer, 1 is accepted
0
Momchil
Telerik team
answered on 08 Jul 2022, 08:15 AM
Hello, Gerardo
The general pattern to create a Kendo Grid hierarchy in ASP.NET Core is the following:
1. Create the parent Grid with HtmlHelpers and configure it based on your needs.
3. Configure the child Grid inside the Kendo Template by using HtmlHelpers. It is important to ensure that the Name() of every child Grid is unique. A good option is to append the unique Model id of parent Grid to the name of the child Grid. For example:
.Name("child_grid_#=ModelId#")
4. Since the child Grid is initialized in a template, it is required to add the ".ToClientTemplate()" option.
5. Specify the name of the template created in Step 2 in the configuration of the parent Grid through the ".ClientDetailTemplateId()" method.
I hope this information helps. Please let me know if I can assist you any further.
Best regards,
Momchil Zanev
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
4. The "DetailInit" event provides the child grid element of the currently expanded master row. By using the "e.detailCell", get a reference of the current child grid. Then use the setDataSource() method to set the DataSource of the child grid with the appropriate data.
<script>
functiononDetailInit(e) {
var childGridElement = e.detailCell.find(".k-grid"); //select the child grid element
var dataSource = new kendo.data.DataSource({ //create a new DataSource component
data: e.data.Orders
});
$(childGridElement).data("kendoGrid").setDataSource(dataSource); //set the DataSource
}
</script>
I am attaching a runnable demo that demonstrates this solution.
Regarding your second question on how to include JavaScript inside a Kendo template:
The template allows you to include HTML, JS code, and HtmlHelpers, so declaring a <script> tag inside it is not a valid syntax. If you would like to add JavaScript inside a Kendo template, check out the following documentation: