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

Can you sort by an Aggregrate function?

5 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
LHR
Top achievements
Rank 1
LHR asked on 08 Sep 2011, 08:37 PM
We have a very large data set, which users can group by a few different columns depending on how they want to see the data. When grouped, there are 3 aggregrates: Count, Sum, and Average. Is there a way to allow the users to sort by these aggregates without pre-defining the groups?

I looked at a few samples I found on your forums for sorting by an aggregate, but they all sorted based on a pre-defined Group, and once you changed the Group, the sorting stopped working.

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 12 Sep 2011, 08:39 AM
Hello Dave,

I guess you are probably referring to approach similar to this one:

public class SortingGroupDescriptor : GroupDescriptor
    {
        public override System.Linq.Expressions.Expression CreateGroupSortExpression(System.Linq.Expressions.Expression groupingExpression)
        {
            if (this.AggregateFunctions.Count == 0)
            {
                return base.CreateGroupSortExpression(groupingExpression);
            }
            else
            {
                return this.AggregateFunctions[0].CreateAggregateExpression(groupingExpression);
            }
        }
    }

In this case the groups will be sorted only based on the aggregates belonging to the corresponding group descriptor, not to the column. You need to make sure that the aggregate you want to sort on is available for the group descriptor - SortingGroupDescriptor.

All the best,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
LHR
Top achievements
Rank 1
answered on 12 Sep 2011, 12:53 PM
Can you post an example of how you would use that?

I primarily would like to be able to sort by an aggregate, without pre-defining the sort order in the XAML code
0
Chris Lynch
Top achievements
Rank 1
answered on 10 Nov 2011, 09:12 PM
Yes can you Provide and example of its use
0
Accepted
Maya
Telerik team
answered on 11 Nov 2011, 05:15 PM
Hi,

Please take a look at this forum thread for a reference and a sample project. Although it targets Silverlight, the idea and implementation should be the same for WPF as well. 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
LHR
Top achievements
Rank 1
answered on 11 Nov 2011, 05:29 PM
Thank you Maya, that looks quite promising.

I won't be able to try it out right away, but from what I can see it looks like it will allow me to sort by an Aggregate while allowing the user to specify how they want the data grouped instead of hardcoding the grouping in the XAML.
Tags
GridView
Asked by
LHR
Top achievements
Rank 1
Answers by
Maya
Telerik team
LHR
Top achievements
Rank 1
Chris Lynch
Top achievements
Rank 1
Share this question
or