Back to Devexpress

Sorting by Summary

aspnet-8456-components-pivot-grid-data-shaping-sorting-sorting-by-summary.md

latest8.4 KB
Original Source

Sorting by Summary

  • Dec 02, 2022
  • 4 minutes to read

Sorting by Summary allows you to sort the current column or row field’s values by corresponding summary values.

The following image illustrates the Pivot Grid Control with Product field values sorted by the USA | Margaret Peacock | Quantity column:

Tip

Demo: Sort by Summary

End-User Sorting by Summary

End-users can sort by summary through the context menu by right-clicking an innermost column or row header.

The image in the row’s/column’s header indicates if the field values are sorted by this row/column.

Sorting by Summary is available for all fields displayed within the Column Header Area or Row Header Area. There are two ways you can disable this functionality for end-users:

PropertyDescriptionNote
PivotGridOptionsCustomization.AllowSortBySummaryGets or sets whether end-users can sort row field values by column values, and column field values by row values.This property affects all fields.
PivotGridFieldOptions.AllowSortBySummaryGets or sets whether end-users can sort the current row/column field values by other column/row summary values.This property affects individual fields.

Note that in this instance, individual fields’ settings take priority over ASPxPivotGrid settings.

Sorting by Summary in Code

Use the field’s PivotGridFieldBase.SortBySummaryInfo property to get access to the settings that are used to sort the values of the current column field or row field by corresponding summary values.

You need to specify a data field whose summary values should define the sort order to sort data by summaries. Do one of the following:

After you specified a data field, ASPxPivotGrid sorts field values by a Grand Total column/row that corresponds to this data field.

The image below shows the Pivot Grid sorted by the Extended Price‘s Grand Total values:

To sort field values by any other column/row or their totals, identify this field by adding sort conditions using the PivotGridFieldSortBySummaryInfo.Conditions property. Each condition is a PivotGridFieldSortCondition object that identifies a field value so that the whole collection identifies a column/row.

Create two sort conditions to sort field values by the Qtr 2 Total column total.

csharp
fieldProductName.SortBySummaryInfo.Field = fieldExtendedPrice;
fieldProductName.SortBySummaryInfo.Conditions.Add(new PivotGridFieldSortCondition(fieldYear, 2016));
fieldProductName.SortBySummaryInfo.Conditions.Add(new PivotGridFieldSortCondition(fieldQuarter, 2));
vb
fieldProductName.SortBySummaryInfo.Field = fieldExtendedPrice
fieldProductName.SortBySummaryInfo.Conditions.Add(New PivotGridFieldSortCondition(fieldYear, 2016))
fieldProductName.SortBySummaryInfo.Conditions.Add(New PivotGridFieldSortCondition(fieldQuarter, 2))

The image below demonstrates the corresponding result:

Create the additional condition to sort data by the specified column/row:

csharp
fieldProductName.SortBySummaryInfo.Field = fieldExtendedPrice;
fieldProductName.SortBySummaryInfo.Conditions.Add(new PivotGridFieldSortCondition(fieldYear, 2016));
fieldProductName.SortBySummaryInfo.Conditions.Add(new PivotGridFieldSortCondition(fieldQuarter, 2));
fieldProductName.SortBySummaryInfo.Conditions.Add(new PivotGridFieldSortCondition(fieldMonth, 5));
vb
fieldProductName.SortBySummaryInfo.Field = fieldExtendedPrice
fieldProductName.SortBySummaryInfo.Conditions.Add(New PivotGridFieldSortCondition(fieldYear, 2016))
fieldProductName.SortBySummaryInfo.Conditions.Add(New PivotGridFieldSortCondition(fieldQuarter, 2))
fieldProductName.SortBySummaryInfo.Conditions.Add(New PivotGridFieldSortCondition(fieldMonth, 5))

Three sort conditions identify the highlighted column on the image below:

You can sort data by a custom total column/row by specifying its type using the PivotGridFieldSortBySummaryInfo.CustomTotalSummaryType property.

Use the PivotGridFieldBase.SortOrder property to specify whether to sort values in ascending or descending order.

Sorting by Summary in OLAP

In OLAP mode, create sort conditions using a PivotGridFieldSortCondition constructor overload that takes an OLAP member’s unique name as a parameter.

Use the ASPxPivotGrid.GetFieldValueOLAPMember method to obtain an OLAP member for a field value. This method returns an object that implements the IOLAPMember interface. To access the OLAP member’s unique name, use its IOLAPMember.UniqueName property.

Limitations

The following Pivot Grid features are not supported or ignored when you sort data by summary:

Examples