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

autogenerate columns with datatable

1 Answer 872 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bert
Top achievements
Rank 1
Veteran
Bert asked on 27 Sep 2020, 06:48 AM

Hi,

I'm retrieving data using a select query into a datatable. When I try to show this data in a grid with the  AutoGenerateColumns=true, the data is not shown.

Is there a way to show the data from a datatable in a grid with automatic generation of the columns? The number of columns in the query are dynamic, before execution of the query I don't know the number of columns.

 

Thanks

 

 

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 27 Sep 2020, 07:40 AM

Hello Bert,

You can loop over the columns collection of the data table to generate the columns in a foreach loop, in a fashion very similar to this example for expando objects: https://github.com/telerik/blazor-ui/blob/master/grid/binding-to-expando-object/BindingToExpandoObject/Pages/AutoGeneratedColumns.razor.

I would suggest you also consider a collection of expnado objects as the grid data source as it offers better built-in integration - it does not require that you alter the data into a collection of dictionaries through the OnRead event.

 

Regards,
Marin Bratanov
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
Bert
Top achievements
Rank 1
Veteran
Answers by
Marin Bratanov
Telerik team
Share this question
or