This is a migrated thread and some comments may be shown as answers.

How to dynamically show/hide and change the display order of Radgrid Columns

1 Answer 1251 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian K
Top achievements
Rank 1
Brian K asked on 28 Aug 2020, 07:25 PM

Hello, I have a radgrid that is associated with a really large table as far as columns.  This table may have 60 columns in which data from different reports are written to this table.  I want to have a drop down that when a value is selected from the dropdown, I can set certain columns to be visible and certain columns to be hidden based on that selected value.  For example report 1 might use columns 1-15, and report 2 might use columns 1-5 and 16-25, so I want to be able to dynamically show and hide columns based on the column name that I plan to store in another table in relation to the report.  So when a user selects a report from a dropdown list, I can query the table that has what columns should be visible for the selected report, and dynamically show/hide columns in the radgrid based on that selection.

 

I am not finding anything in the documentation for this.  Any idea/suggestions would be appreciated.  Thanks.

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 02 Sep 2020, 04:22 PM

Hi Brian,

To hide a column on the client-side you can use the hideColumn JavaScript method.

On the server, you can wire up the PreRender event of the Grid, loop through the columns or just get the column by its UniqueName and set its Visible property to false. Here is a Forum thread for this: how to hide columns in radgrid

Based on your description the RadGrid may contain a totally different set of data that would require different columns. For that best would be to define the Radgrid in the markup and have Autogenerated columns, or in case you would like to have Custom columns, create the Grid programmatically for each set of data. See Creating a RadGrid Programmatically for more details.

Regards,
Attila Antal
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
Grid
Asked by
Brian K
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or