DxGridDataColumn.AllowSort Property

Specifies whether users can sort data in this column.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.1.dll

Declaration

[Parameter]
public bool? AllowSort { get; set; }

Property Value

Type Description
Nullable<Boolean>

true to allow users to sort column data; otherwise, false.

Remarks

The DxGrid allows users to sort its data.

  • To apply sorting for one column, users can click the column header. They can click the header again to change the sort order. The sort glyph indicates the column’s current sort order.

  • To sort the Grid against multiple columns, users should click column headers with the Shift key pressed.

  • To clear sorting, users can hold the Ctrl key and click the column headers.

Sort Data

Set the AllowSort property to false to disable sorting for an individual column.

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

<DxGrid Data="GridDataSource"
        CustomizeCellDisplayText="OnCustomizeCellDisplayText">
    <Columns>
        <DxGridDataColumn FieldName="OrderDate"
                      DisplayFormat="d" />
        <DxGridDataColumn FieldName="Customer"
                      AllowSort="false" />
        <DxGridDataColumn FieldName="Freight"
                      DisplayFormat="n2" />
    </Columns>
</DxGrid>

@code {
    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})";
        }
    }
}

To disable sorting for the entire grid, use the DxGrid.AllowSort property.

Note

You can use the column’s SortIndex property or SortBy method to sort data in code regardless of the AllowSort property value.

Run Demo: Grid - Sort Data

Implements

See Also