Provides the ability to sort data using custom rules.
public event PivotCustomFieldSortEventHandler CustomFieldSort
Public Event CustomFieldSort As PivotCustomFieldSortEventHandler
The CustomFieldSort event's data class is PivotCustomFieldSortEventArgs. The following properties provide information specific to this event:
|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 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.
- 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.
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 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.
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 optimized engine sorts the aggregated data. The legacy engine raises the CustomFieldSort event more often to compare different rows of data. The optimized 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.
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.