# Conditionally Hide Expand Icons for the Detail Template in the Grid

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Grid</td> 
 </tr>
 <tr>
  <td>Product Version</td>
  <td>2024.1.130</td>
 </tr>
</table>

## Description

How can I hide the expand icon for the detail template in a Telerik UI for ASP.NET MVC Grid based on a `HasChildren` value that is defined as Model property?

## Solution

1. Traverse the rows of the parent Grid within the [`DataBound`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/grideventbuilder#databoundsystemstring) event.
2. To retrieve the data item, access the `<tr>` element by using the [`dataItem()`](https://docs.telerik.com/kendo-ui/api/ui/grid/methods/dataitem) client-side method of the Grid.
3. Conditionally hide the icon based on the `HasChildren` field.

```Razor Index.cshtml
    <script id="template" type="text/kendo-tmpl">
        @(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)
        .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)        
         )
    )
```

```C# Parent.cs
    public class Parent {
        public int Id {get;set;}
        public string ParentName {get;set;}
        public bool HasChildren {get;set;}
    }
```

```C# Child.cs
    public class Child {
        public int Id {get;set;}
        public int ParentId {get;set;}
        public string ChildName {get;set;}
    }
```

```JS script.js
    <script>
        function onDataBound(e){
            var items = e.sender.items(); // 1. Gather the DOM element representations of the rows.
            items.each(function(){ // 2. Traverse through each of the rows.
              var dataItem = e.sender.dataItem(row); // 3. Obtain the dataItem counter-part of the row.
              if(!dataItem.HasChildren){ // 4. Assert the for the HasChildren field.
                row.find(".k-hierarchy-cell").html(""); // 5. Hide the expand icon.
              }
            })
        }
    </script> 
```

For a full implementation of the aforementioned approach, refer to the [REPL example on conditionally hiding the expand icon of the Grid's Detail template](https://netcorerepl.telerik.com/woORlIlT18ecGZdO25).

## More ASP.NET MVC Grid Resources

* [ASP.NET MVC Grid Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/overview)

* [ASP.NET MVC Grid Demos](https://demos.telerik.com/aspnet-mvc/grid/index)

* [ASP.NET MVC Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/grid)

* [Server-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)

* [Hide Expand Icon Based on Field Value Telerik REPL (HtmlHelper)](https://netcorerepl.telerik.com/woORlIlT18ecGZdO25)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
