PivotGridControl.CustomServerModeSort Event
In OLAP and server mode, provides the capability to sort data using custom rules.
Namespace: DevExpress.Xpf.PivotGrid
Assembly: DevExpress.Xpf.PivotGrid.v24.1.dll
NuGet Package: DevExpress.Wpf.PivotGrid
Declaration
Event Data
The CustomServerModeSort event's data class is CustomServerModeSortEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Field | Gets the field whose values are being compared. |
OlapMember1 | Get the first member being compared. |
OlapMember2 | Get the second member being compared. |
Result | Gets or sets the result of a custom comparison. |
ThreadSafeField | |
Value1 | Gets the first value being compared. |
Value2 | Gets the second value being compared. |
The event data class exposes the following methods:
Method | Description |
---|---|
GetCellValue1(CrossAreaKey, PivotGridField) | In OLAP and server mode, returns the first cell value calculated for the specified cross area key against the specified data field. |
GetCellValue1(Object[], PivotGridField) | In OLAP and server mode, returns the first cell value calculated for the specified cross area field values against the specified data field. |
GetCellValue2(CrossAreaKey, PivotGridField) | In OLAP and server mode, returns the second cell value calculated for the specified cross area key against the specified data field. |
GetCellValue2(Object[], PivotGridField) | In OLAP and server mode, returns the second cell value calculated for the specified cross area field values against the specified data field. |
GetCrossAreaKey(Object[]) | In OLAP and server mode, returns cross area values by which you want to sort the pivot grid column or row. |
SetArgs(IQueryMemberProvider, IQueryMemberProvider, IPivotGridField, PivotGridData, ICustomSortHelper) |
Remarks
Note
The PivotGridField.SortMode property of the sorted field should be set to Custom to apply custom sorting. Otherwise, the CustomServerModeSort event will not be raised.
Example: Implement a Custom Sorting Algorithm
This example demonstrates how to implement a custom sorting algorithm by handling the CustomServerModeSort event. The “Month” column field is sorted by the “Produce” row using the cross area key, and the “Confections” field is sorted directly by the 1998 year.
using System.Windows;
using DevExpress.Xpf.PivotGrid;
using System.Collections;
namespace WPFPivotGridCustomServerModeSort {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
PivotGridField field = fieldOrderYear;
pivotGridControl1.BeginUpdate();
try {
field.FilterValues.Clear();
field.FilterValues.Add(1998);
field.FilterValues.FilterType = FieldFilterType.Included;
}
finally {
pivotGridControl1.EndUpdate();
}
fieldCategoryName.SortMode = FieldSortMode.Custom;
fieldOrderMonth.SortMode = FieldSortMode.Custom;
}
private void pivotGridControl1_CustomServerModeSort(object sender,
CustomServerModeSortEventArgs e) {
// Sorting using a cross area object.
if (e.Field == fieldOrderMonth) {
// Sets the cross area key, by which the "Month" field will be sorted.
// In this example, it's one of the "Category" cross area field values.
CrossAreaKey sorting = e.GetCrossAreaKey(new object[] { "Confections" });
// Sets the result of the "Month" field's values comparison
// by the cross area key object and the "Price" field.
e.Result = Comparer.Default.Compare(
e.GetCellValue1(sorting, fieldPrice),
e.GetCellValue2(sorting, fieldPrice)
);
}
// Direct sorting without using a cross area object.
if (e.Field == fieldCategoryName) {
// Sets the result of "Category" field's values comparison by the Year and Price fields.
e.Result = Comparer.Default.Compare(
e.GetCellValue1(new object[] { 1998 }, fieldPrice),
e.GetCellValue2(new object[] { 1998 }, fieldPrice)
);
}
}
}
}