Skip to main content
A newer version of this page is available. .
Tab

ASPxCardView.CustomColumnSort Event

Enables you to sort data using custom rules.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v19.2.dll

Declaration

public event ASPxCardViewCustomColumnSortEventHandler CustomColumnSort

Event Data

The CustomColumnSort event's data class is CardViewCustomColumnSortEventArgs. The following properties provide information specific to this event:

Property Description
Column Gets the column whose values are being compared.
Handled Gets or sets whether a comparison operation is handled, and therefore, no default processing is required. Inherited from GridCustomColumnSortEventArgs.
ListSourceRowIndex1 Gets the index in the data source of the first of the two data items (row, card or record) being compared. Inherited from GridCustomColumnSortEventArgs.
ListSourceRowIndex2 Gets the index in the data source of the second of the two data items (row, card or record) being compared. Inherited from GridCustomColumnSortEventArgs.
Result Gets or sets the result of a custom comparison. Inherited from GridCustomColumnSortEventArgs.
SortOrder Gets the sort order applied to the column (row for ASPxVerticalGrid) being processed. Inherited from GridCustomColumnSortEventArgs.
Value1 Gets the first value being compared. Inherited from GridCustomColumnSortEventArgs.
Value2 Gets the second value being compared. Inherited from GridCustomColumnSortEventArgs.

The event data class exposes the following methods:

Method Description
GetRow1Value(String) Returns the specified column’s value in the first data item (row, card or record) being compared. Inherited from GridCustomColumnSortEventArgs.
GetRow2Value(String) Returns the specified column’s value in the second data item (row, card or record) being compared. Inherited from GridCustomColumnSortEventArgs.

Remarks

A column’s Settings.SortMode (GridDataColumnSettings.SortMode) property specifies how the grid’s data is sorted when sorting is applied to this column. If this property is set to ‘Custom’, a custom sorting algorithm can be implemented for this column by handling the CustomColumnSort event.

When the CustomColumnSort event is fired, two cards should be compared. The column being processed is specified by the CustomColumnSortEventArgs.Column parameter. The GridCustomColumnSortEventArgs.Value1 and GridCustomColumnSortEventArgs.Value2 parameters identify the row values within this column.

The result of the custom comparison should be set to the GridCustomColumnSortEventArgs.Result parameter as shown below:

  • set Result to -1 if the first card should be positioned above the second card when data is sorted in ascending order. When data is sorted in descending order, the first card will be positioned below the second card.
  • set Result to 1 if the first card should be positioned below the second card when data is sorted in ascending order. When data is sorted in descending order, the first card will be positioned above the second card.
  • set Result to 0 to indicate that the cards are equal. In this case, the cards will be arranged within the grid according to their indexes in the data source.

The GridCustomColumnSortEventArgs.Handled parameter should be set to true if the current comparison operation was handled. You can leave this parameter set to false to invoke the default comparison mechanism after your event handler has finished. In this case, the custom comparison operation’s result is ignored.

Example

The following example implements custom sorting. The “Country” column displays text values. When sorting is applied to this column, the cards are compared by the length of the “Country” column values.

Note that custom sorting must be enabled for the “Country” column (its GridDataColumnSettings.SortMode property is set to ‘Custom’).

The image below shows the result:

ASPxCardView_CustomcolumnsortEvent

protected void CardView_CustomColumnSort(object sender, CardViewCustomColumnSortEventArgs 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;
    }
}
See Also