Skip to main content
Tab

ASPxGridBehaviorSettings.SortMode Property

Specifies how the control sorts its data.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.2.dll

Declaration

[DefaultValue(ColumnSortMode.Default)]
public ColumnSortMode SortMode { get; set; }

Property Value

Type Default Description
ColumnSortMode Default

One of the ColumnSortMode enumeration values.

Available values:

Name Description
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 control’s sort algorithm. When the grid’s SortMode property is set to Default, the control applies the Value sort algorithm.

To apply custom sort settings to the grid control, follow the steps below:

  1. Set the SortMode property to Custom.
  2. Handle the ASPxGridView.CustomColumnSort, ASPxCardView.CustomColumnSort, or ASPxVerticalGrid.CustomRowSort event.

At the column level, use the GridDataColumnSettings.SortMode property to specify how the control sorts data in a particular column (a row for ASPxVerticalGrid).

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

Example

The example below sorts data in the grid by character length.

ASPxGridView - GridSortMode

<dx:ASPxGridView ID="grid" runat="server" OnCustomColumnSort="grid_CustomColumnSort">
    <%--...--%>
    <SettingsBehavior SortMode="Custom" />
</dx:ASPxGridView>
protected void grid_CustomColumnSort(object sender, DevExpress.Web.CustomColumnSortEventArgs e) {
    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;
}

Online Demos

Run Demo: ASPxGridView - Sort Data

Run Demo: ASPxCardView - Sorting

Run Demo: ASPxVerticalGrid - Sorting

See Also