Skip to main content
A newer version of this page is available. .

DxGridDataColumn.SortIndex Property

Specifies the column’s index among sorted columns.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.1.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

The Grid cannot group and sort data by the same column. If you set a column’s SortIndex and GroupIndex properties to non-negative values, 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

Implements

See Also