Sorting Data by Group Summaries
- 3 minutes to read
The ExpressQuantumGrid provides you with the two following options to sort data in Grid Views:
by the column and card row content (available for tabular and Card Views);
by group values or group summary values (available for grouped tabular Views only).
Both these options can be switched and customized with ease both at design time and runtime.
This topic describes the methods related to the second option. Refer to the Sorting Data topic for more information on the first option.
When a tabular View is grouped by any column, group rows are automatically sorted by group values provided by this column. End-users can reverse the sort order of group rows by clicking a grouped column header or using the Column Header Popup Menu.
To programmatically specify the sort order, use a grouped column’s SortOrder property. Refer to the Sorting Data topic for a code example on how this can be accomplished.
In addition to this standard method of sorting data in grouped Views, you can specify group rows to be sorted using group summary values calculated at the corresponding level.
The following image shows the View grouped by the Payment Type column.
In this View, the following two group summaries are calculated in data groups:
- A group row summary calculated against the values of the Payment Amount column;
- A group footer summary calculated against the values of the Quantity column.
End-users can choose the sort method from the Group Row Popup Menu.
As a result, group rows are sorted using the values of the selected summary.
In code, this can be done via:
A required summary item’s Sorted property. At design time, you can access a summary item’s properties by clicking the corresponding group summary in a group row or group footer;
The Summary.SortByGroupFooterSummary or Summary.SortByGroupSummary property of a column whose summary values will be used for sorting.
The grouped column controls the order in which group rows are displayed when sorted by summary values. End-users can change this order in the standard manner.
Tabular Views provide a special indication if their group rows are sorted by summary values. A horizontal line painted above or below the sort glyph (depending on the skin or look and feel style applied) gives a visual cue for columns whose grouped rows are sorted by summary values.
To apply a style to group summary values used to determine the sort order, use the View’s Styles.GroupSortedSummary and Styles.GroupFooterSortedSummary properties. The following images display the View with these group summaries painted blue.
Note
Sorting by summary values cannot be performed if summaries are calculated for the selected records only (either the soSelectedRecords or soMultipleSelectedRecords flag is set via the data controller’s Summary.Options property).