Skip to main content

DxGrid.CustomSort Event

Allows you to implement custom logic used to sort data in the grid.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.dll

NuGet Package: DevExpress.Blazor


public Action<GridCustomSortEventArgs> CustomSort { get; set; }


Type Description

Provides access to grid data.


Follow the steps below to implement custom logic used to sort data in the DxGrid.

  1. Set the SortMode property to Custom.
  2. Handle the CustomSort event to implement your logic that compares column values. When the event fires, the component compares two row values: the Value1 and Value2 properties. To define the column’s sort algorithm, set the Result property to one of the following values:

    Value Description
    -1 The grid places the first data item above the second item in ascending sort mode and below the second item in descending sort mode.
    1 The grid places the first data item below the second item in ascending sort mode and above the second item in descending sort mode.
    0 Indicates that the data items are equivalent according to the comparison condition. The grid sorts them based on their indices in the data source.
  3. Set the Handled property to true to indicate that the current comparison operation is handled. If the value is set to false, the component ignores the result of the custom comparison and uses the default mechanism to compare item values.


The Grid does not support custom sorting when you use a Server Mode data source or GridDevExtremeDataSource.

The code below implements custom logic to sort the Order Date column’s values without taking into account the year part of the date.

@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable

<DxGrid Data="GridDataSource"
        <DxGridDataColumn FieldName="OrderDate"
        <DxGridDataColumn FieldName="ShipName" />
        <DxGridDataColumn FieldName="ShipCity" />
        <DxGridDataColumn FieldName="Freight"

@code {
    object GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }

    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        GridDataSource = Northwind.Orders.ToList();

    void OnCustomSort(GridCustomSortEventArgs e) {
        if(e.FieldName == "OrderDate") {
            var date1 = Convert.ToDateTime(e.Value1);
            var date2 = Convert.ToDateTime(e.Value2);

            if(date1.Month == date2.Month)
                e.Result = date1.Day.Compare(date2.Day);
                e.Result = date1.Month.Compare(date2.Month);
            e.Handled = true;

    public void Dispose() {

Grid - Custom Sorting

Watch Video: Grid - Sort Data

View Example: Grid - Custom Sorting

For more information about data sorting in the Grid component, refer to the following topic: Sort Data in Blazor Grid.

See Also