Skip to main content

DxGrid.GetSortedColumns() Method

Gets the collection of sorted columns.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public IReadOnlyList<IGridDataColumn> GetSortedColumns()

Returns

Type Description
IReadOnlyList<IGridDataColumn>

The column collection.

Remarks

Use the GetSortedColumns method to get the collection of sorted columns. Note that a grouped column is always sorted.

The following code snippet obtains the first item from the sorted column collection:

@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="@OnGetSortedColumns">Get First Sorted Column</DxButton>
@Alert

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

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

    void OnGetSortedColumns() {
        string FirstSortedColumnName = MyGrid.GetSortedColumns().FirstOrDefault()?.FieldName;
        Alert = "The first sorted column is " + FirstSortedColumnName;
    }

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

Grid - Get First Sorted Column

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

Implements

See Also