Skip to main content
A newer version of this page is available. .

Sorting Data

  • 2 minutes to read

Sort Order

The PivotGridControl‘s data (and nested values in groups) are sorted by fields in the Column Header Area and Row Header Area. The default sort order is ascending.

To change a field’s sort order, specify the PivotGridFieldBase.SortOrder property or click the pivot grid field’s header.

In the picture below, the data rows are sorted alphabetically in ascending order by the Product Name field. The data columns are sorted in ascending order by the Order Date field.

cdSortOrderProperty

Sort Modes

The sort mode determines the attribute by which to sort field values. You can use the PivotGridFieldBase.SortMode property to specify the sort mode for each field.

When a pivot grid obtains its data from a non-OLAP data source, you can sort field values by the value itself (default mode), by the field’s displayed text, or implement a custom sorting algorithm as shown in the following table:

Sort Mode

Description

PivotSortMode.Value

Field values are sorted in alphabetical order (for text data) or in ascending order (for numeric and date/time data).

PivotSortMode.DisplayText

You can sort values by the displayed (formatted) text instead of the original field values if numeric field values are formatted in the PivotGridControl.FieldValueDisplayText event handler.

PivotSortMode.Custom

The PivotGridControl.CustomFieldSort event fires. Implement a field value comparison within the event handler and set the PivotGridCustomFieldSortEventArgsBase<T>.Result value depending on the comparison result.

Note that in a server mode, the PivotGridControl.CustomServerModeSort event fires instead.

When a pivot grid obtains its data from an OLAP data source, you can sort field values by the value itself (default mode) or by the field’s display text. the following OLAP-specific modes are also in effect:

Sort Mode Description
PivotSortMode.DimensionAttribute Sorts the field values by an OLAP member’s property. Assign the OLAP member property name to the field’s PivotGridFieldBase.SortByAttribute property. To get a list of OLAP member properties, call the PivotGridFieldBase.GetOLAPMemberProperties method.
PivotSortMode.ID Sorts by a level member’s ID (in OLAP mode).
PivotSortMode.Key Sorts the field’s data by key attributes (in OLAP mode).
PivotSortMode.None Data is not sorted - it is displayed in the order the data source specifies. This option is in effect only in OLAP mode.
PivotSortMode.Custom The PivotGridControl.CustomServerModeSort event fires. Implement a field value comparison within the event handler and set the PivotGridCustomFieldSortEventArgsBase<T>.Result value depending on the comparison result.
See Also