New to Telerik UI for ASP.NET Core? Start a free 30-day trial
Conditionally Hide Expand Icons for the Detail Template in the Grid
Environment
Product | Telerik UI for ASP.NET Core Grid |
Product Version | 2024.1.130 |
Description
How can I hide the expand icon for the detail template in a Telerik UI for ASP.NET Core Grid based on a HasChildren
value that is defined as Model property?
Solution
- Traverse the rows of the parent Grid within the
DataBound
event. - To retrieve the data item, access the
<tr>
element by using thedataItem()
client-side method of the Grid. - Conditionally hide the icon based on the
HasChildren
field.
Razor
<script id="template" type="text/kendo-tmpl"> // Child Grid
@(Html.Kendo().Grid(@childData)
.Name("grid#=Id#")
.Columns(columns =>
{
columns.Bound(p => p.ChildName).Title("Child Name");
})
.Pageable()
.Sortable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(false)
)
.ToClientTemplate()
)
</script>
@(Html.Kendo().Grid(@parentData) // Parent Grid
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.ParentName).Title("Parent Name");
})
.Events(events => events.DataBound("onDataBound"))
.Pageable()
.Sortable()
.Filterable()
.ClientDetailTemplateId("template")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(false)
)
)
For a full implementation of the aforementioned approach, refer to the following Telerik REPL examples: