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

[Solved] Setting an initial sort expression

1 Answer 75 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.
Craig Fisher
Top achievements
Rank 1
Craig Fisher asked on 29 Mar 2011, 11:52 PM
I want to do an initial sort on a date column such that null values appear first and then non-nulls in descending order.

Using LINQ I can do it like this:
ListItemSet.OrderByDescending(d=>d.RequestDate == null).ThenByDescending(r=>r.RequestDate)
or
ListItemSet.OrderByDescending(d=>d.RequestDate == null ? DateTime.Now : d.RequestDate)

How can I achieve the same with the grid?

I tried this, but it doesn't work:
    .Sortable(s=>s.OrderBy(f=>f.Add(r=>(r.RequestDate == null) ? DateTime.Now : r.RequestDate).Descending()))

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 30 Mar 2011, 07:09 AM
Hi Craig Fisher,

 You can specify only a member expression (property or field access) in the Sortable grid method:
.Sortable(sorting => sorting.OrderBy(sortOrder => sortOrder.Add(o => o.RequestDate).Descending()))

Currently you cannot specify different criteria (as in your case) for the same column. The only option you have is to sort the data before binding it to the grid.

Regards,
Atanas Korchev
the Telerik team
Tags
Grid
Asked by
Craig Fisher
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or