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

DxGrid.AllowSort Property

Specifies whether users can sort grid data.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[DefaultValue(true)]
[Parameter]
public bool AllowSort { get; set; }

Property Value

Type Default Description
Boolean true

true to allow users to sort grid 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 Grid’s AllowSort property to false to prevent users from sorting grid data. The column’s AllowSort property allows you to specify whether users can sort grid data by this column. Note that the value specified at the column level overrides that of the component level.

Note

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

The example below demonstrates how to prevent users from sorting grid data:

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

<DxGrid Data="GridDataSource"
        AllowSort="false">
    <Columns>
        <DxGridDataColumn FieldName="OrderDate"
                          DisplayFormat="d" />
        <DxGridDataColumn FieldName="ShipName" />
        <DxGridDataColumn FieldName="ShipCity" />
        <DxGridDataColumn FieldName="Freight"
                          DisplayFormat="n2" />
    </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();
    }
}

Run Demo: Grid - Sort Data Watch Video: Grid - Sort Data

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

Implements

See Also