Skip to main content

DxGridDataColumn.SortIndex Property

Specifies the column’s index among sorted columns. If the property is set to -1, the grid data is not sorted by this column.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[DefaultValue(-1)]
[Parameter]
public int SortIndex { get; set; }

Property Value

Type Default Description
Int32 -1

The column’s index (zero-based) among sorted columns. -1 if the grid does not sort data by this column.

Remarks

The SortIndex property allows you to sort grid data by an individual column in code. In this case, sorting is applied regardless of the DxGrid.AllowSort or DxGridDataColumn.AllowSort property value.

If you sort data by multiple columns, this property specifies the sort level. For instance, the grid first sorts data by a column with SortIndex = 0 and then by a column with SortIndex = 1. If you set this property to -1, data is not sorted by the corresponding column.

Note

Only one of SortIndex and GroupIndex can be set to a non-negative value. Otherwise, the Grid raises an exception.

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

<DxGrid Data="GridDataSource">
    <Columns>
        <DxGridDataColumn FieldName="OrderDate"
                          DisplayFormat="d"
                          SortIndex="1" />
        <DxGridDataColumn FieldName="ShipName" />
        <DxGridDataColumn FieldName="ShipCity" />
        <DxGridDataColumn FieldName="Freight"
                          DisplayFormat="n2"
                          SortIndex="0"
                          SortOrder="GridColumnSortOrder.Descending" />
    </Columns>
</DxGrid>

@code {
    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 - SortIndex

Run Demo: Grid - Sort Data

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.

Implements

See Also