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

DxGrid.GroupBy(String) Method

Groups data by values of the specified data source field.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public void GroupBy(
    string fieldName
)

Parameters

Name Type Description
fieldName String

Specifies the name of the data source field that supplies data for the grouped column.

Remarks

The GroupBy method allows you to group grid data in code regardless of the DxGrid.AllowGroup or DxGridDataColumn.AllowGroup property value.

The code below demonstrates how to use different method overloads.

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

<DxGrid Data="GridDataSource"
        ShowGroupPanel="true"
        CustomizeCellDisplayText="OnCustomizeCellDisplayText"
        @ref="@MyGrid">
    <Columns>
        <DxGridDataColumn FieldName="OrderDate"
                      DisplayFormat="d"
                      GroupInterval="GridColumnGroupInterval.DateMonth" />
        <DxGridDataColumn FieldName="Customer"
                      SortMode="GridColumnSortMode.DisplayText"
                      GroupInterval="GridColumnGroupInterval.DisplayText" />
        <DxGridDataColumn FieldName="Freight"
                      DisplayFormat="n2"/>
    </Columns>
</DxGrid>

<DxButton Click="@(() => MyGrid.GroupBy("OrderDate"))">Group by OrderDate</DxButton>
<DxButton Click="@(() => MyGrid.GroupBy("Customer", 0))">Group by Customer, Group Index = 0</DxButton>

@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 - GroupBy Method

Implements

See Also