Back to Devexpress

PivotGridControl.CustomFieldSort Event

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridcontrol-97817884.md

latest6.6 KB
Original Source

PivotGridControl.CustomFieldSort Event

Provides the ability to sort data using custom rules.

Namespace : DevExpress.Xpf.PivotGrid

Assembly : DevExpress.Xpf.PivotGrid.v25.2.dll

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
public event PivotCustomFieldSortEventHandler CustomFieldSort
vb
Public Event CustomFieldSort As PivotCustomFieldSortEventHandler

Event Data

The CustomFieldSort event's data class is PivotCustomFieldSortEventArgs. The following properties provide information specific to this event:

PropertyDescription
FieldGets the field whose values are sorted.
HandledGets or sets whether a comparison operation is handled and no default processing is required.
ListSourceRowIndex1Gets the index in the data source of the first of the two rows being compared.
ListSourceRowIndex2Gets the index in the data source of the second of the two rows being compared.
ResultGets or sets the result of a custom comparison.
SortLocationGets a target UI element whose items are sorted.
SortOrderGets the sort order applied to the field.
ThreadSafeFieldGets the field whose values are being compared. Provides read-only access to field settings.
Value1Gets the first field value to compare.
Value2Gets the second value to compare.

The event data class exposes the following methods:

MethodDescription
GetListSourceColumnValue(Int32, String)Gets a value from the specified row and column.

Remarks

The CustomFieldSort event occurs for the field whose SortMode property is set to the FieldSortMode.Customvalue. Handle the CustomFieldSort event to provide a custom sorting algorithm for the field values.

In OLAP or server mode, use the PivotGridControl.CustomServerModeSort event instead.

Important

The CustomFieldSort event is not supported in Optimized mode.

The CustomFieldSort event fires for pairs of field values before they are grouped according to the layout of column and row fields. To establish a new sort order, perform the following actions:

  1. Get values to compare from the e.Value1 and e.Value2 properties.

  2. Compare these values and assign the result to the e.Result property as follows:

  3. Set the e.Handled property to true to finalize the comparison and use the e.Result value. Otherwise, the default comparison is in effect and e.Result is ignored.

Note

The CustomFieldSort event occurs in different situations in PivotDataProcessingEngine.Legacy and PivotDataProcessingEngine.LegacyOptimized modes because of the different workflow - the Legacy engine aggregates data after sorting performed at the data source level, while the LegacyOptimized engine sorts the aggregated data. The Legacy engine raises the CustomFieldSort event more often to compare different rows of data. The LegacyOptimized engine raises the event to compare the resulting data groups.

However, you can still use the e.ListSourceRowIndex1 and e.ListSourceRowIndex2 properties and the e.GetListSourceColumnValue method. They return the data from the first data row included in the processed group.

How to Sort Filter Values in Filter Drop-Down

Handle the CustomFieldSort event to sort unique filter values in the Filter Drop-Down. To determine whether the data comes from the filter, check the e.SortLocation property - its value is FieldSortLocation.Filter or FieldSortLocation.GroupFilter.

Important

A field value in a filter relates to multiple rows in the underlying data source. The ListSourceRowIndex1 and ListSourceRowIndex2 properties are always -1 when the event fires for the field located in the Filter Drop-Down.

See Also

PivotGridControl Class

PivotGridControl Members

DevExpress.Xpf.PivotGrid Namespace