I''ve followed the example, SortBySUmmaryInCaption and it does not do what I need regarding sorting with summaries.
If I add 3 summary columns (SUM, MIN, MAX), and then let the USER group by dragging a column to the group bar, I want the the user to be able to sort by those three columns (or any other columns), so that when collapsed, the sorting is in the Aggregates (SUM, MIN, mAX), but when expanded, it is sorted by the underlying values.
I know that I can attach to the grid.TableDescriptor.GroupedColumns.Changed event, which returns the SortColumnDescriptor that is added / removed by the user... do I then have to track what columns have been sorted and reset my own sort handlers?
FOR EXAMPLE:
Run the SortBySUmmaryInCaption demo example, remove the ShipCountry from the group, and then group by EmployeeID by dragging to the group bar.
Now, click the Freight column. Since the freight column contains a summary column with averages of freight, and while groups are collapsed, I would expect the groups to sort by Freight. When the user clicks Freight again, I would expect a reverse sort.
AD
Administrator
Syncfusion Team
April 18, 2006 02:13 PM UTC
Hi Robishaw,
The sort order of the groups can be reversed by just calling sortColumnDescriptor.SetGroupSummarySortOrder(), passing the intent sort order. Below is a code snippet. Please try this in the SortBySUmmaryInCaption sample and let us know if you need any further assistance.
this.gridGroupingControl1.TableControlQueryAllowSortColumn += new GridQueryAllowSortColumnEventHandler(gridGroupingControl1_TableControlQueryAllowSortColumn);//Add this event handler.
ListSortDirection sortDir = ListSortDirection.Ascending;
private void gridGroupingControl1_TableControlQueryAllowSortColumn(object sender, GridQueryAllowSortColumnEventArgs e)
{
foreach(Group g in this.gridGroupingControl1.Table.TopLevelGroup.Groups)
{
if(g.IsExpanded)
return;
}
if(this.gridGroupingControl1.TableDescriptor.GroupedColumns.Count>0)
{
GridSummaryRowDescriptor summaryRow = this.gridGroupingControl1.TableDescriptor.SummaryRows["Caption"];
GridSummaryColumnDescriptor summary= summaryRow.SummaryColumns["FreightAverage"];
SortColumnDescriptor gsd = this.gridGroupingControl1.TableDescriptor.GroupedColumns[0];
if(sortDir == ListSortDirection.Ascending)
{
sortDir = ListSortDirection.Descending;
gsd.SetGroupSummarySortOrder(summary.GetSummaryDescriptorName(), "Average",sortDir);
}
else
{
sortDir = ListSortDirection.Ascending;
gsd.SetGroupSummarySortOrder(summary.GetSummaryDescriptorName(), "Average",sortDir);
}
}
}
Regards,
Calvin.
SF
Stuart Faircloth
May 22, 2007 01:14 AM UTC
Hi Calvin,
This solution appears to work if you just want to sort for 1 column. If you require sorting on multiple columns it will only sort on the last column selected.
Do you know how to solve my problem?
Thanks
Stuart
>Hi Robishaw,
>
>The sort order of the groups can be reversed by just calling sortColumnDescriptor.SetGroupSummarySortOrder(), passing the intent sort order. Below is a code snippet. Please try this in the SortBySUmmaryInCaption sample and let us know if you need any further assistance.
>
>this.gridGroupingControl1.TableControlQueryAllowSortColumn += new GridQueryAllowSortColumnEventHandler(gridGroupingControl1_TableControlQueryAllowSortColumn);//Add this event handler.
>
>
> ListSortDirection sortDir = ListSortDirection.Ascending;
> private void gridGroupingControl1_TableControlQueryAllowSortColumn(object sender, GridQueryAllowSortColumnEventArgs e)
> {
> foreach(Group g in this.gridGroupingControl1.Table.TopLevelGroup.Groups)
> {
> if(g.IsExpanded)
> return;
> }
> if(this.gridGroupingControl1.TableDescriptor.GroupedColumns.Count>0)
> {
> GridSummaryRowDescriptor summaryRow = this.gridGroupingControl1.TableDescriptor.SummaryRows["Caption"];
> GridSummaryColumnDescriptor summary= summaryRow.SummaryColumns["FreightAverage"];
> SortColumnDescriptor gsd = this.gridGroupingControl1.TableDescriptor.GroupedColumns[0];
> if(sortDir == ListSortDirection.Ascending)
> {
> sortDir = ListSortDirection.Descending;
> gsd.SetGroupSummarySortOrder(summary.GetSummaryDescriptorName(), "Average",sortDir);
> }
> else
> {
> sortDir = ListSortDirection.Ascending;
> gsd.SetGroupSummarySortOrder(summary.GetSummaryDescriptorName(), "Average",sortDir);
>
> }
>
> }
> }
>
>Regards,
>Calvin.