PivotGridControl.CustomFieldSort Event
Provides the ability to sort data using custom rules.
Namespace: DevExpress.Xpf.PivotGrid
Assembly: DevExpress.Xpf.PivotGrid.v24.2.dll
NuGet Package: DevExpress.Wpf.PivotGrid
Declaration
Event Data
The CustomFieldSort event's data class is PivotCustomFieldSortEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Field | Gets the field whose values are sorted. |
Handled | Gets or sets whether a comparison operation is handled and no default processing is required. |
ListSourceRowIndex1 | Gets the index in the data source of the first of the two rows being compared. |
ListSourceRowIndex2 | Gets the index in the data source of the second of the two rows being compared. |
Result | Gets or sets the result of a custom comparison. |
SortLocation | Gets a target UI element whose items are sorted. |
SortOrder | Gets the sort order applied to the field. |
ThreadSafeField | Gets the field whose values are being compared. Provides read-only access to field settings. |
Value1 | Gets the first field value to compare. |
Value2 | Gets the second value to compare. |
The event data class exposes the following methods:
Method | Description |
---|---|
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:
- Get values to compare from the e.Value1 and e.Value2 properties.
Compare these values and assign the result to the e.Result property as follows:
- -1 if the first value should be placed before the second value when values are sorted in ascending order. When values are sorted in descending order, the first value is after the second value.
- 1 if the first value should be placed after the second value when values are sorted in ascending order. When values are sorted in descending order, the first value is placed before the second value.
- 0 to indicate that the values are equal. The rows are grouped into one field value.
Note
Values are sorted before grouping. If the values are equal (the e.Result is set to 0), they are in the same group.
To get additional field values from the data source, call the e.GetListSourceColumnValue method with the following parameters:
- Set row index parameter to the e.ListSourceRowIndex1 or e.ListSourceRowIndex2 value
- Set the column name parameter to the field name. The current field name is available with the e.Field.FieldName property.
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.