I try to use a RadzenGrid to display a dynamic table. The columns of the table are configured in a JSON file, so I don't know in advance what they will be. I am using a List < ExpandoObject > to get the data and can successfully display it but sorting and filtering doesn't work as the underlying code seems to be unable to access the dynamics members in my ExpandoObject. My grid looks like this:
"result" is a List < ExpandoObject > and "columns" a IDictionary < string, object > which contains the columns with an id -> label mapping. At the same time, the ids are members of the ExpandoObject. Displaying the grid works fine, but when I try to sort or filter, I get error messages like this:
warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
Unhandled exception rendering component: No property or field 'System_Title' exists in type 'ExpandoObject'
No property or field 'System_Title' exists in type 'ExpandoObject' (at index 0)
Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: No property or field 'System_Title' exists in type 'ExpandoObject'
Would you have any ideas how to fix this? Or maybe better ideas how to display a dynamically generated table? I also tried using a DataTable or DataView as data element but couldn't figure out how that might work as well
The Radzen Blazor DataGrid uses Linq expressions to perform sorting and filtering (via Dynamic Linq). The latter won't work with ExpandoObjects. You can try using dynamic though. It could work.
Would you mind posting a more complete example of your code? I don't see where the results and columns variables are being declared and set. I'm trying to do something similar. You must have created a custom class for your results containing an "Items" and a "TotalCount" field, but I don't know how you are defining the columns.
Hi , I have one custom class for TotalCount and Items.
where ToatlCount is of type int and Items is of type List<ExpandoObject>. Columns is a dictionary. Dictionary<string, object> columns = new Dictionary<string, object>();
which simply store columns. on which we are iterating.
Yes, I understand now. Thanks. I didn't realize that the "columns" dictionary was just a property/field on the page.
I've learned as a result of doing some testing using Radzen that its easier to manipulate the service to get the data the way you want it and then pass that data model to the page. If I expose what I want in the data model, then all the native Radzen tools work with it easily.
How to make the DataGrid editable with ExpandoObject?
My original requirement was to bind DataTable to DataGrid but researching led me to this post so i transformed my DataTable to ExpandoObject for binding but now I am stuck how to make it editable also? Or any other way because data is dynamics and there could be any number of columns in DataTable.
I am new to Blazor. I have to create Encapsulated Dynamic grid control from API data. How to do OnInitializedAsync(). Can you share your code file.
Thanks for your concern