Skip to main content

DxGrid.SortBy(String) Method

Sorts data by the specified column values.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public void SortBy(
    string columnFieldName
)

Parameters

Name Type Description
columnFieldName String

Specifies the name of the data source field that supplies data for the processed column. If the component does not contain the column that corresponds to the specified data field, an exception occurs.

Remarks

The SortBy method allows you to sort grid data in code regardless of the DxGrid.AllowSort or DxGridDataColumn.AllowSort property value.

The following code snippet uses different method overloads.

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

<DxGrid Data="GridDataSource"
        @ref="MyGrid">
    <Columns>
        <DxGridDataColumn FieldName="OrderDate"
                          DisplayFormat="d"/>
        <DxGridDataColumn FieldName="ShipName" />
        <DxGridDataColumn FieldName="ShipCity" />
        <DxGridDataColumn FieldName="Freight"
                          DisplayFormat="n2"
                          SortIndex="0"/>
    </Columns>
</DxGrid>

<DxButton Click="@(() => MyGrid.SortBy("OrderDate"))">Sort By Order Date</DxButton>
<DxButton Click="@(() => MyGrid.SortBy("OrderDate", GridColumnSortOrder.Descending))">Sort By Order Date (Descending Order)</DxButton>
<DxButton Click="@(() => MyGrid.SortBy("OrderDate", GridColumnSortOrder.Descending, 0))">Sort By Order Date (Descending Order, SortIndex = 0)</DxButton>

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

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

    public void Dispose() {
        Northwind?.Dispose();
    }
}

Grid - Sort By Amount

Watch Video: Grid - Sort Data

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

Implements

See Also