Back to Devexpress

GridDataColumnSettings.SortMode Property

aspnet-devexpress-dot-web-dot-griddatacolumnsettings-491f2c9f.md

latest5.1 KB
Original Source

GridDataColumnSettings.SortMode Property

Specifies how the control sorts data in a column (a row for ASPxVerticalGrid).

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(ColumnSortMode.Default)]
public ColumnSortMode SortMode { get; set; }
vb
<DefaultValue(ColumnSortMode.Default)>
Public Property SortMode As ColumnSortMode

Property Value

TypeDefaultDescription
ColumnSortModeDefault

One of the ColumnSortMode enumeration values.

|

Available values:

NameDescription
Default

The actual sort mode is determined by a control. See the property description for more details.

| | 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 |

Applies sort options specified in the CustomColumnSort event handler.

In data grids, this mode also applies group options from the CustomColumnGroup event handler.

|

Remarks

Specify the SortMode property to define the column’s sort algorithm.

When a column’s SortMode property is set to Default, the column behaves as follows:

To apply custom sort settings to a column, follow the steps below:

  1. Set the SortMode property to Custom.

  2. Handle the ASPxGridView.CustomColumnSort, ASPxVerticalGrid.CustomRowSort, or ASPxCardView.CustomColumnSort event.

Example

The example below sorts the Country column by character length in descending order.

aspx
<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>
csharp
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;
    }
}
vb
Protected Sub grid_CustomColumnSort(ByVal sender As Object, ByVal e As DevExpress.Web.CustomColumnSortEventArgs)
    If e.Column.FieldName = "Country" Then
        e.Handled = True
        Dim s1 As String = e.Value1.ToString(), s2 As String = e.Value2.ToString()

        If s1.Length > s2.Length Then
            e.Result = 1
        ElseIf s1.Length = s2.Length Then
            e.Result = Comparer.[Default].Compare(s1, s2)
        Else
            e.Result = -1
        End If
    End If
End Sub

For more information on the sort mode in a particular control, refer to the following topics:

Online Demos

Run Demo: ASPxGridView - Sort Data

Run Demo: ASPxCardView - Sorting

Run Demo: ASPxVerticalGrid - Sorting

See Also

GridDataColumnSettings Class

GridDataColumnSettings Members

DevExpress.Web Namespace