GridDataColumnSettings.SortMode Property
Specifies how the control sorts data in a column (a row for ASPxVerticalGrid).
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v21.2.dll
NuGet Package: DevExpress.Web
Declaration
Property Value
Type | Default | Description |
---|---|---|
ColumnSortMode | Default | One of the ColumnSortMode enumeration values. |
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
Specify the SortMode
property to define the column’s sort algorithm. To apply custom sort settings to a column, follow the steps below:
Set the
SortMode
property toCustom
.Handle the ASPxGridView.CustomColumnSort, ASPxVerticalGrid.CustomRowSort, or ASPxCardView.CustomColumnSort event.
Example
The example below sorts the Country column by character length in descending order.
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="false"
OnCustomColumnSort="grid_CustomColumnSort">
<Columns>
<dx:GridViewDataColumn FieldName="Country" SortOrder="Descending">
<Settings SortMode="Custom" />
</dx:GridViewDataColumn>
<%--...--%>
</Columns>
</dx:ASPxGridView>
protected void grid_CustomColumnSort(object sender, DevExpress.Web.CustomColumnSortEventArgs e) {
if(e.Column.FieldName == "Country") {
e.Handled = true;
string s1 = e.Value1.ToString(), s2 = e.Value2.ToString();
if(s1.Length > s2.Length)
e.Result = 1;
else
if(s1.Length == s2.Length)
e.Result = Comparer.Default.Compare(s1, s2);
else
e.Result = -1;
}
}
For more information on the sort mode in a particular control, refer to the following topics: