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

DxGrid.TotalSummary Property

Contains total summary items.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public RenderFragment TotalSummary { get; set; }

Property Value

Type Description
RenderFragment

A collection of total summary items (UI fragment) that the browser renders in the grid’s markup.

Remarks

The DxGrid calculates total summary values across all records and displays these values in the footer. To create the total summary, declare a DxGridSummaryItem object in the TotalSummary template and specify the SummaryType and FieldName properties.

You can set the SummaryType property to Custom and handle the CustomSummary event to create a custom summary item.

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

<DxGrid Data="GridDataSource"
        UnboundColumnData="Grid_CustomUnboundColumnData">
    <Columns>
        <DxGridDataColumn FieldName="ProductId" Caption="Product ID" DisplayFormat="d" />
        <DxGridDataColumn FieldName="UnitPrice" />
        <DxGridDataColumn FieldName="Quantity" />
        <DxGridDataColumn FieldName="Discount" DisplayFormat="p0" />
        <DxGridDataColumn FieldName="TotalPrice"
                      DisplayFormat="c"
                      UnboundType="GridUnboundColumnType.Decimal" />
    </Columns>
    <TotalSummary>
        <DxGridSummaryItem SummaryType="GridSummaryItemType.Sum" FieldName="TotalPrice" />
        <DxGridSummaryItem SummaryType="GridSummaryItemType.Max"
                           FieldName="UnitPrice"
                           ValueDisplayFormat="c"                           
                           FooterColumnName="TotalPrice" />
    </TotalSummary>
</DxGrid>
@* ... *@
@code {
    object GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }

    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        GridDataSource = Northwind.OrderDetails
            .Include(i => i.Order)
            .Include(i => i.Product)
            .ToList();
    }

    void Grid_CustomUnboundColumnData(GridUnboundColumnDataEventArgs e) {
        if (e.FieldName == "TotalPrice") {
            var UnitPrice = Convert.ToDecimal(e.GetRowValue("UnitPrice"));
            var Quantity = Convert.ToDecimal(e.GetRowValue("Quantity"));
            var Discount = Convert.ToDecimal(e.GetRowValue("Discount"));
            e.Value = Quantity * UnitPrice * (1 - Discount);
        }
    }

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

DevExpress Blazor Grid - Total Summary

To refresh all total summary values in the Grid component, call the RefreshSummary() method.

Run Demo: Grid - Total Summary Watch Video: Grid - Summary

See Also