This question is locked. New answers and comments are not allowed.
Hi,
This is not exactly a telerik question but maybe you guys can help me out! :)
I have this code:
It's the sorting part I'm wondering about.
If I have a lot of columns in my grid then I would need to add a huge number of cases in the switch.
Is it possible to do something like:
Is it possible to add a GetProperty method somehow or is there another way to solve this?
Regards,
Mattias
This is not exactly a telerik question but maybe you guys can help me out! :)
I have this code:
| [GridAction] |
| public ActionResult Index(GridCommand command) |
| { |
| MenuRepository rep = new MenuRepository(); |
| List<System.Linq.Expressions.Expression<Func<Menu, object>>> expressions = new List<System.Linq.Expressions.Expression<Func<Menu, object>>>(); |
| List<System.Linq.Expressions.Expression<Func<Menu, object>>> expressionsDesc = new List<System.Linq.Expressions.Expression<Func<Menu, object>>>(); |
| //Apply sorting |
| foreach (SortDescriptor sortDescriptor in command.SortDescriptors) |
| { |
| if (sortDescriptor.SortDirection == ListSortDirection.Ascending) |
| { |
| switch (sortDescriptor.Member) |
| { |
| case "Name": |
| expressions.Add(m => m.Name); |
| break; |
| default: |
| expressions.Add(m => m.Name); |
| break; |
| } |
| } |
| else |
| { |
| switch (sortDescriptor.Member) |
| { |
| case "Name": |
| expressionsDesc.Add(m => m.Name); |
| break; |
| default: |
| expressions.Add(m => m.Name); |
| break; |
| } |
| } |
| } |
| int totalPages = 0; |
| IEnumerable<Menu> menus = rep.GetPagedMenus<Menu>(null, null, expressions, expressionsDesc, command.Page, command.PageSize, out totalPages); |
| ViewData["total"] = totalPages; |
| return View(menus); |
| } |
If I have a lot of columns in my grid then I would need to add a huge number of cases in the switch.
Is it possible to do something like:
| //Apply sorting |
| foreach (SortDescriptor sortDescriptor in command.SortDescriptors) |
| { |
| if (sortDescriptor.SortDirection == ListSortDirection.Ascending) |
| { |
| expressions.Add(m => m.GetProperty(sortDescriptor.Member)); |
| } |
| else |
| { |
| expressionsDesc.Add(m => m.GetProperty(sortDescriptor.Member)); |
| } |
| } |
Is it possible to add a GetProperty method somehow or is there another way to solve this?
Regards,
Mattias