Skip to main content

DxGridDataColumn.GroupIndex Property

Specifies the column’s index among grouped columns.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[DefaultValue(-1)]
[Parameter]
public int GroupIndex { get; set; }

Property Value

Type Default Description
Int32 -1

The column’s index (zero-based) among grouped columns. -1 if the grid does not group data by this column.

Remarks

Use the GroupIndex property to group data by an individual column in code. In this case, grouping is applied regardless of the DxGrid.ShowGroupPanel, DxGrid.AllowGroup, and DxGridDataColumn.AllowGroup property values.

If you group data by multiple columns, this property specifies the group level. The lower the value, the higher a column’s group level. For instance, the grid first groups data by a column with GroupIndex = 0 and then by a column with GroupIndex = 1. If you set this property to -1, data is not grouped by the corresponding column.

Note

Only one of SortIndex and GroupIndex can be set to a non-negative value. Otherwise, the Grid raises an exception.

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

<DxGrid Data="GridDataSource"
        ShowGroupPanel="true"
        CustomizeCellDisplayText="OnCustomizeCellDisplayText">
    <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>

@code {
    object GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }

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

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

Grid - GroupIndex

Run Demo: Grid - Group Data

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

Implements

See Also