This project is read-only.

Using Expando objects to create column collection

Apr 7, 2014 at 5:34 PM
Edited Apr 7, 2014 at 5:35 PM
Hi All,

I have a requirement where I cannot create a class for the data in the view model as the properties change. It is being passed as an list of expand objects. I have been trying to use the Columns.Add in various ways to get the grid to populate. I should note that data only needs to be displayed and filtering enabled not bound or editable.
The latest attempt is:

item = Model[0];
foreach (var kv in (IDictionary<string, object>)item)
                   string colname = kv.Key.ToString();
                    grid2.Columns.Add().RenderValueAs(c => ((IDictionary<string, object>)item)[colname].ToString()).Titled(kv.Key).Filterable(true);
This populates the headers properly but repeats the first item values in all rows of the grid.

Is there another way to dynamically specify the column definitions from the expando object property dictionary?