Dear Syncfusion,
I am reading your documentation about binding your Blazor grid to a dynamic /ExpandoObject. In both cases you are emphasizing the fact that the structure of these objects are not know in compile time. However in your examples you are binging the columns to fixed field names.
Let's assume, I want to show in the grid the result of the SELECT * FROM @TableName query result, where the @TableName is given to the query in runtime. Clearly the column names are not know in compile time, moreover even the number of columns can be arbitrary. Can you please guide me to a solution? What steps should I take to create such dynamic grid.
One more important thing: the grid is read-only. There is no need to modify the data, it is only for display.
Thanks!
|
<SfGrid @ref="grid"
Height="400px"
Width="100%"
TValue="ExpandoObject"
DataSource=@data>
<GridColumns>
@if (data != null && data.Any())
{
var firstItem = data.First();
var dictionaryItem = (IDictionary<string, object>)firstItem;
var fields = dictionaryItem.Keys;
foreach (var item in dictionaryItem)
{
<GridColumn Field="@item.Key"></GridColumn>
}
}
</GridColumns>
</SfGrid> |
Dear Jeevakanth,
thank you for the quick answer. Your suggestion made me a step forward: now all the fields title appears in the grid. However the grid rows are empty, they are not showing any data. It seems the number of rows are fine, but no data shown.
Dear Jeevakanth,
thank you very much for the full sample you provided. Based on that I was able to rewrite my app, what now works well.
Thanks again for the help!