Showing and Hiding Columns and data Conditionally

2 Answers 15 Views
Grid GridLayout
Charlston
Top achievements
Rank 1
Iron
Charlston asked on 19 Nov 2025, 12:40 PM

I am converting a MVC table grid to a Telerik Grid. While looking at it, there are conditional columns. For example: 

 


@if (Model?.GroupDetail?.IsMec == false)
                                    {
                                        <th class="text-secondary" style="width: 140px;">Group Info</th>
                                    }

<th class="text-secondary">
                                        @if (Model?.GroupDetail?.IsMec == false)
                                        {
                                            <text>Office</text>
                                        }
                                        else
                                        {
                                            <text>Role</text>
                                        }
                                    </th>
How would I go about recreating something like this for the grid 

2 Answers, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 24 Nov 2025, 07:47 AM

Hi Charlston,

Thank you for the details provided.

You can recreate the conditional column rendering from your MVC table in the Telerik Grid for ASP.NET Core by using server-side logic for column definition and dynamic header text. Here’s how you can approach this:

  • Conditional Column Visibility:
    In the grid’s Columns configuration, use your model property to decide whether to include or hide a column:

    @(Html.Kendo().Grid<ModelType>()
        .Name("grid")
        .Columns(columns =>
        {
            if (Model?.GroupDetail?.IsMec == false)
            {
                columns.Bound(p => p.GroupInfo).Title("Group Info");
            }
            columns.Bound(p => p.OfficeOrRole)
                .Title(Model?.GroupDetail?.IsMec == false ? "Office" : "Role");
        })
        // Additional grid configuration...
    )
    
  • Dynamic Header Text:
    Set the column title based on your condition, as shown above.

  • Client-side Alternative:
    If you need to switch column visibility or header text after the grid is rendered (for example, based on user interaction), you can use the grid’s client-side API with JavaScript:

    function onDataBound(e) {
        var grid = this;
        if (isMec) {
            grid.hideColumn("GroupInfo");
            grid.columns[1].title = "Role";
        } else {
            grid.showColumn("GroupInfo");
            grid.columns[1].title = "Office";
        }
        grid.refresh();
    }

For more information:

 

    Kind Regards,
    Anton Mironov
    Progress Telerik

    Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

    0
    Charlston
    Top achievements
    Rank 1
    Iron
    answered on 24 Nov 2025, 10:28 AM
    Thank you 
    Anton Mironov
    Telerik team
    commented on 27 Nov 2025, 07:51 AM

    Hi Charlston,

    Thank you for the kind words. If additional information or assistance is needd, feel free to contact me and the Team.

     

    Best Regards,
    Anton Mironov

    Tags
    Grid GridLayout
    Asked by
    Charlston
    Top achievements
    Rank 1
    Iron
    Answers by
    Anton Mironov
    Telerik team
    Charlston
    Top achievements
    Rank 1
    Iron
    Share this question
    or