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

DxGrid.CustomSummary Event

Specifies data for custom summary items.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public Action<GridCustomSummaryEventArgs> CustomSummary { get; set; }

Parameters

Type Description
GridCustomSummaryEventArgs

A GridCustomSummaryEventArgs object that contains data for this event.

Remarks

Handle the CustomSummary event to compute total or group summaries based on custom logic. For more information, refer to the following topic: Add a Custom Summary Item.

Use GridCustomSummaryEventArgs (TotalValue, FieldValue, and so on) to evaluate the summary value and to access other grid data.

Note

The Grid does not support custom summary calculation when you use a GridDevExtremeDataSource.

The example below illustrates how to create a custom summary item, whose value is evaluated and formatted within the CustomSummary and CustomizeSummaryDisplayText event handlers.

<DxGrid Data="GridDataSource"
        UnboundColumnData="Grid_CustomUnboundColumnData"
        CustomizeSummaryDisplayText="Grid_CustomizeSummaryDisplayText"
        CustomSummary="Grid_CustomSummary">
    <Columns>
        <DxGridDataColumn FieldName="ProductId" 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.Custom" Name="Custom" FieldName="ProductId" />
    </TotalSummary>
</DxGrid>
@* ... *@
@code {
    object GridDataSource { get; set; }
    int totalCount;

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

    void Grid_CustomSummary(GridCustomSummaryEventArgs e) {
        if (e.SummaryStage == GridCustomSummaryStage.Start)
            totalCount = 0;
        else if (e.SummaryStage == GridCustomSummaryStage.Calculate) {
            if (Convert.ToInt16(e.GetValue("UnitPrice")) < 20)
                totalCount++;
        }
        else if (e.SummaryStage == GridCustomSummaryStage.Finalize)
            e.TotalValue = totalCount;
    }

    void Grid_CustomizeSummaryDisplayText(GridCustomizeSummaryDisplayTextEventArgs e) {
        if (e.Item.Name == "Custom")
            e.DisplayText = string.Format("Count (Unit Price < 20): {0}", e.Value);
    }
    @* ... *@
}

DevExpress Blazor Grid - Custom Summary

Run Demo: Grid - Custom Summary

See Also