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.v21.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public int SortIndex { get; set; }

Property Value

Type Description
Int32

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.

@using Microsoft.EntityFrameworkCore
@using Grid.Northwind
@inject NorthwindContext Northwind

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

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

    protected override void OnInitialized() {
        GridDataSource = Northwind.Orders
            .Include(i => i.Customer)
            .Include(i => i.OrderDetails)
            .Include(i => i.ShipViaNavigation)
            .ToList();
    }

    void OnCustomizeCellDisplayText(GridCustomizeCellDisplayTextEventArgs e) {
        if (e.FieldName == "Customer") {
            var customer = (Customer)e.Value;
            e.DisplayText = $"{customer.CompanyName} ({customer.Country}, {customer.City})";
        }
    }
}

Grid - SortIndex

Run Demo: Grid - Sort Data

Implements

See Also