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

[Solved] Sorting Groups

1 Answer 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
alex
Top achievements
Rank 1
alex asked on 29 Jan 2008, 05:47 PM
I have a grid displaying a list of objects that have a Date field.

I want to group these by: those with a Date of "Today", "Yesterday" and "Older than that". I also want so that the Today group comes before the yesterday group, etc.

Alphabetically, "Older.." comes before "Today" which comes before "Yesterday".

How do I get the grid to group by these categories with clean titles, and order the groups as desired?

One of my attempts was:

I created another field in the objects that returns an enum corresponding to these states. Unfortunately, there is no way to override ToString for enums, or to specify how to sort them.

I then created a DateRegion object and added a field in my object class that returns a DateRegion object. This object has a Text Field that corresponds to the categories above. Unfortunately the grid seems to sort alphabetically by this Text.

Any ideas? Am I being clear?

1 Answer, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 01 Feb 2008, 05:16 PM
Hi alex,

You can achieve the desired functionality with two auxiliary fields (one will be numeric and will be used for the sorting -- PeriodSortable in the sample, the other will contain the friendly string you want to display -- Period in the sample).

Then you can instruct the grid to group by PeriodSortable but display the friendly alias like this:

<GroupByExpressions> 
    <telerik:GridGroupByExpression> 
        <GroupByFields> 
            <telerik:GridGroupByField FieldName="PeriodSortable" FieldAlias="TimePeriod" /> 
        </GroupByFields> 
        <SelectFields> 
            <telerik:GridGroupByField FieldName="Period" HeaderText="&nbsp;" HeaderValueSeparator="&nbsp;" /> 
        </SelectFields> 
    </telerik:GridGroupByExpression> 
</GroupByExpressions> 


We have attached the sample application for your reference as well. Hope this helps.


Regards,
Manuel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
alex
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Share this question
or