ColumnBase.SortMode Property
Gets or sets how the column’s data is sorted when sorting is applied to it. This is a dependency property.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v21.2.Core.dll
NuGet Package: DevExpress.Wpf.Grid.Core
Declaration
Property Value
Type | Default | Description |
---|---|---|
ColumnSortMode | Default | A ColumnSortMode enumeration value that specifies the sort mode. |
Available values:
Name | Description |
---|---|
Default | Sorts the column’s data according to the type of the editor assigned to the column. The Default option is equivalent to DisplayText for columns that use LookUpEdit, ImageComboBoxEdit and HypertextLabel (RepositoryItemHypertextLabel) in-place editors. The Default option is equivalent to Value for other columns. Note that for certain editors (TextEdit, ComboBoxEdit, etc) the edit values match the display values. |
Value | Sorts the column’s data by the column’s edit values (these are synchronized with the bound data source’s values). |
DisplayText | Sorts the column’s data by the column’s display text (the strings displayed within the column’s cells). |
Custom | Enables custom sorting of a column’s data. To implement custom sorting, handle the ColumnView.CustomColumnSort event in the GridControl, and the TreeList.CompareNodeValues event in the TreeList. In the GridControl, the Custom mode also enables custom grouping of rows when grouping is applied against the current column. To implement custom grouping, handle the GridView.CustomColumnGroup event. |
Remarks
The SortMode property specifies the algorithm used to sort the column’s data (by display text, edit value or using a custom sorting algorithm).
To provide custom sorting and/or grouping, set the SortMode property to ‘Custom’ and handle the GridControl.CustomColumnSort and GridControl.CustomColumnGroup events.
Tip
Topic: Sorting Modes and Custom Sorting.
Example
The following example demonstrates how to use custom rules to sort data in the GridControl:
<dxg:GridControl x:Name="grid"
CustomColumnSort="OnCustomColumnSort">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Day" GroupIndex="0" SortMode="Custom"/>
<dxg:GridColumn FieldName="Employee"/>
</dxg:GridControl.Columns>
</dxg:GridControl>
void OnCustomColumnSort(object sender, CustomColumnSortEventArgs e) {
if(e.Column.FieldName == "Day") {
int dayIndex1 = GetDayIndex(e.Value1);
int dayIndex2 = GetDayIndex(e.Value2);
e.Result = dayIndex1.CompareTo(dayIndex2);
e.Handled = true;
}
}
int GetDayIndex(object day) {
return (int)Enum.Parse(typeof(DayOfWeek), (string)day);
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the SortMode property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.