Skip to main content

DxGrid.GetGroupCount() Method

Gets the number of grouped columns.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public int GetGroupCount()

Returns

Type Description
Int32

Specifies the number of grouped columns.

Remarks

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

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

<DxButton Click="@OnGetGroupCount">Get Group Count</DxButton>

@Alert

@code {
    IGrid MyGrid { get; set; }
    object GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    public string Alert { get; set; } = "";
    int count;

    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        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})";
        }
    }

    void OnGetGroupCount() {
        count = MyGrid.GetGroupCount();
        Alert = "The group count equals " + count;
    }

    public void Dispose() {
        Northwind?.Dispose();
    }
}

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

Implements

See Also