This question is locked. New answers and comments are not allowed.
Hello,
For the sake of DRY principle, we would like to have only 1 view per object type and define which columns should be displayed by adding Expression<Func<T, object>> to a setting object that will hold the collection and the all settings for the table.
So we use this item to hold every columns.
We add the columns in the controller :
And in the view, we would like to be able to choose which columns should be displayed by iterating over the Columns expressions.
But this doesn't work.
Does anyone have any idea how I'm supposed to achieve that ?
Thanks.
For the sake of DRY principle, we would like to have only 1 view per object type and define which columns should be displayed by adding Expression<Func<T, object>> to a setting object that will hold the collection and the all settings for the table.
public class TelerikTableSettings<T> where T : IEORTCObject { public string Name { get; set; } public ICollection<T> Items { get; set; } public ICollection<Expression<Func<T, object>>> Columns {get;set;} public TelerikTableSettings() { this.Name = typeof(T).Name; this.Columns = new List<Expression<Func<T, object>>>(); } public void AddColumn(Expression<Func<T, object>> property) { if (!this.Columns.Contains(property)) this.Columns.Add(property); } }So we use this item to hold every columns.
We add the columns in the controller :
public ActionResult Index() { TelerikTableSettings<Group> settings = new TelerikTableSettings<Group>(); settings.Items = prismaManager.GroupManager.Select(); settings.AddColumn(g => g.Name); settings.AddColumn(g => g); return View(settings); }And in the view, we would like to be able to choose which columns should be displayed by iterating over the Columns expressions.
.Columns(columns => { foreach(var col in Model.Columns) { columns.Bound(g => col.Compile().DynamicInvoke(g)); } })But this doesn't work.
Does anyone have any idea how I'm supposed to achieve that ?
Thanks.