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

DxGridSummaryItem.SummaryType Property

Specifies the summary function type.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[DefaultValue(GridSummaryItemType.None)]
[Parameter]
public GridSummaryItemType SummaryType { get; set; }

Property Value

Type Default Description
GridSummaryItemType None

A GridSummaryItemType enumeration value.

Available values:

Name Description
Sum

Calculates the sum of all values in a column.

Min

Calculates the minimum value of all values in a column.

Max

Calculates the maximum value of all values in a column.

Count

Calculates the number of values in a column.

Avg

Calculates the average of all values in a column.

Custom

Uses a custom algorithm to calculate a summary value.

None

Does not calculates a summary value.

Remarks

Use the summary item’s SummaryType property to specify an aggregate function to calculate the total and group summary values.

Predefined Summary Functions

The Grid supports the predefined Sum, Min, Max, Avg, and Count functions.

The Avg, Min, Max, and Sum functions require that you set the FieldName property to a data field whose values take part in calculations. The Min and Max functions require a numeric or date-time data field. The Avg and Sum functions work with numeric fields only.

If you select the Count function, do not change the FieldName property and use the FooterColumnName property to specify which column displays the summary value.

@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
@* ... *@
<DxGrid Data="GridDataSource"
        UnboundColumnData="Grid_CustomUnboundColumnData"
        ShowGroupPanel="true">
    <Columns>
        <DxGridDataColumn FieldName="Order.ShipName" Caption="Contact Name" />
        <DxGridDataColumn FieldName="Order.ShipCountry" Caption="Country" />
        <DxGridDataColumn FieldName="Order.ShipCity" Caption="City" />
        <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>
    <GroupSummary>
        <DxGridSummaryItem SummaryType="GridSummaryItemType.Max"
                           ValueDisplayFormat="c"
                           FieldName="UnitPrice" />
    </GroupSummary>
    <TotalSummary>
        <DxGridSummaryItem SummaryType="GridSummaryItemType.Sum" FieldName="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 - Summaries

Run Demo: Grid - Total Summary Run Demo: Grid - Group Summary

Watch Video: Grid - Summary

Custom Summary Functions

You can create custom summary items.

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

<DxGrid Data="GridDataSource"
        UnboundColumnData="Grid_CustomUnboundColumnData"
        CustomizeSummaryDisplayText="Grid_CustomizeSummaryDisplayText"
        CustomSummary="Grid_CustomSummary"
        AllowSelectRowByClick="true"
        SelectedDataItems="@SelectedDataItems"
        SelectedDataItemsChanged="Grid_SelectedDataItemsChanged"
        @ref="Grid">
    <Columns>
        <DxGridSelectionColumn />
        <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.Custom" Name="Custom" FieldName="TotalPrice" />
    </TotalSummary>
</DxGrid>

@code {
    IEnumerable<object> GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    IReadOnlyList<object> SelectedDataItems { get; set; }
    IGrid Grid { get; set; }

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

    void Grid_CustomSummary(GridCustomSummaryEventArgs e) {
        switch (e.SummaryStage) {
            case GridCustomSummaryStage.Start:
                e.TotalValue = 0m;
                break;
            case GridCustomSummaryStage.Calculate:
                if (e.Grid.IsDataItemSelected(e.DataItem))
                    e.TotalValue = (decimal)e.TotalValue + (decimal)e.GetRowValue("TotalPrice");
                break;
            case GridCustomSummaryStage.Finalize:
                e.TotalValueReady = true;
                break;
        }
    }

    void Grid_CustomizeSummaryDisplayText(GridCustomizeSummaryDisplayTextEventArgs e) {
        if (e.Item.Name == "Custom")
            e.DisplayText = string.Format("Sum of Selected: {0:c}", e.Value);
    }

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

    void Grid_SelectedDataItemsChanged() {
        Grid.RefreshSummary();
    }

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

DevExpress Blazor Grid - Custom Summary

Run Demo: Grid - Custom Summary

Implements

See Also