This is a migrated thread and some comments may be shown as answers.

[Solved] Custom Sorting

3 Answers 181 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Greg Lynne
Top achievements
Rank 1
Greg Lynne asked on 09 Sep 2010, 11:05 PM
Is it possible to do custom sorting on the MVC data grid similar to what you are doing with the RadGrid. I have found an example for the RadGrid here http://demos.telerik.com/aspnet-ajax/grid/examples/programming/sort/defaultcs.aspx (where it sorts by the name length, not the name), I would like to do a similar thing with the MVC grid. What In am trying to do is sort an entire column but only based on 'n' conditions, not the data itself. This will then set the background color of the cells based on the sort.

3 Answers, 1 is accepted

Sort by
0
Accepted
Peter
Top achievements
Rank 1
answered on 10 Sep 2010, 10:01 AM
Hi,

I think you need to check this online example.

It will help you to implement your requirements.

Regards,
Peter.
0
Greg Lynne
Top achievements
Rank 1
answered on 13 Sep 2010, 09:23 PM
Hi Peter,

Thanks for your response. I had already implemented the solution you proposed but It was not quite what I was after. I need to be able to default the other 11 columns to the Default Alpha sort without having to create 2 cases for every column, as this starts to get large and messy. So out of 12 columns, I only need 1 to be custom and the other 11 need to be the default sort. Is this possible or do I need to implement a switch() case  for every one.

Andrew
0
Greg Lynne
Top achievements
Rank 1
answered on 13 Sep 2010, 09:37 PM
Problem Solved!
I have implemented a "default" case which uses the sortDescriptor.Member attribute on order by and made sure my data implementes IQueryable<>. This takes care of the other 11 columns. Thanks for your help.

---- See Code Below ----
default:
    data = data.OrderBy(ExpressionBuilder.Expression<TaskDto, string>(sortDescriptor.Member));
    break;
Tags
Grid
Asked by
Greg Lynne
Top achievements
Rank 1
Answers by
Peter
Top achievements
Rank 1
Greg Lynne
Top achievements
Rank 1
Share this question
or