New to Telerik UI for ASP.NET CoreStart a free 30-day trial

Conditionally Hide Expand Icons for the Detail Template in the Grid

Environment

ProductTelerik UI for ASP.NET Core Grid
Product Version2024.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

  1. Traverse the rows of the parent Grid within the DataBound event.
  2. To retrieve the data item, access the <tr> element by using the dataItem() client-side method of the Grid.
  3. 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:

More ASP.NET Core Grid Resources

See Also