Sorting Data
- 2 minutes to read
The ExpressPivotGrid provides a flexible sorting mechanism so that you and your end-users can easily locate the desired data by a specific value or find a value by its display data.
Sort Order
Data within the ExpressPivotGrid is always sorted against the column fields and row fields. Their values are sorted in ascending order by default. If values are displayed hierarchically, the values in the child groups are also sorted.
Field values are sorted in alphabetical order (for text data) and in order of magnitude (for numeric and date-time data). The order in which the field values are sorted is specified by a field’s SortOrder property. End-users can do the same by clicking the field header.
The sections below relate to sorting field values in standard data binding modes only. In OLAP mode, you can specify how field values are sorted in certain dimensions using a dimension SortMode property.
Custom Sorting Algorithms
Field values in the ExpressPivotGrid control can be sorted using a custom sorting algorithm. These algorithms are handy when you need to sort field values by the displayed text or using some custom logic. To implement a custom sorting algorithm, handle the pivot grid’s OnCompare event. For instance, you have to handle this event when you provide the display text for grouping values by handling a field’s OnGetGroupValueDisplayText event.
The OnCompare event parameters allow you to determine the field whose values are being compared and to return the result of a comparison of these values.
Sort by Summaries
Each field can also be sorted by the corresponding grand total values instead of its own values. A field’s SortBySummaryInfo property contains the settings used to sort the values of a column field or row field by the grand total values calculated against another field. Use the SortBySummaryInfo.Field and SortBySummaryInfo.SummaryType properties to specify the field whose summaries should be used for sorting and the summary function used to calculate these summaries, respectively.