This question is locked. New answers and comments are not allowed.
Hi,
I've got a base class NamedObject and many classes that descend from it. I need to display objects of descendent classes in the grid, each descendant class has got its own specific set of "columns" (properties). Please can you advise how I can tell the Grid which class type to use to automatically generate the columns? If I just pass-in an IEnumerable<NamedObject> then the grid gives me columns of NamedObject, but I need to display columns of the actual type of the data that I'm passing into the grid. Is there a way to achieve this without duplicating the below code block for every descendant class type?
Thanks.
Pavels.
-------------------------------------
Code Block:
-------------------------------------
@{ Html.Telerik().Grid((IEnumerable<NamedObject>)ViewData["ModuleEntityObjects"])
.Name("MainGrid")
.HtmlAttributes(new { style = "float: left" })
.Columns(columns => { columns.AutoGenerate(true); columns.Command(commands => { commands.Edit(); commands.Delete(); }); })
.ToolBar(commands => commands.Insert())
.DataKeys(keys => keys.Add(f => f.ID))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("SelectObject", ModuleSystemName)
.Insert("InsertObject", ModuleSystemName)
.Update("ModifyObject", ModuleSystemName)
.Delete("DeleteObject", ModuleSystemName))
.Sortable(sorting => sorting
.OrderBy(order => order.Add(o => o.Name))
.Enabled(true))
.Filterable(filtering => filtering.Enabled(true))
.Resizable(resizing => resizing.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Render();
}
I've got a base class NamedObject and many classes that descend from it. I need to display objects of descendent classes in the grid, each descendant class has got its own specific set of "columns" (properties). Please can you advise how I can tell the Grid which class type to use to automatically generate the columns? If I just pass-in an IEnumerable<NamedObject> then the grid gives me columns of NamedObject, but I need to display columns of the actual type of the data that I'm passing into the grid. Is there a way to achieve this without duplicating the below code block for every descendant class type?
Thanks.
Pavels.
-------------------------------------
Code Block:
-------------------------------------
@{ Html.Telerik().Grid((IEnumerable<NamedObject>)ViewData["ModuleEntityObjects"])
.Name("MainGrid")
.HtmlAttributes(new { style = "float: left" })
.Columns(columns => { columns.AutoGenerate(true); columns.Command(commands => { commands.Edit(); commands.Delete(); }); })
.ToolBar(commands => commands.Insert())
.DataKeys(keys => keys.Add(f => f.ID))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("SelectObject", ModuleSystemName)
.Insert("InsertObject", ModuleSystemName)
.Update("ModifyObject", ModuleSystemName)
.Delete("DeleteObject", ModuleSystemName))
.Sortable(sorting => sorting
.OrderBy(order => order.Add(o => o.Name))
.Enabled(true))
.Filterable(filtering => filtering.Enabled(true))
.Resizable(resizing => resizing.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Render();
}