How to: Implement Custom Sorting

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:


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;
            if (s1.Length == s2.Length)
                e.Result = Comparer.Default.Compare(s1, s2);
                e.Result = -1;