DxGrid.CustomSummary Event
Allows you to create custom summary items.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v23.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public Action<GridCustomSummaryEventArgs> CustomSummary { get; set; }
Parameters
Type | Description |
---|---|
GridCustomSummaryEventArgs | An object that contains data for this event. |
Remarks
Grid allows you to calculate group and total summaries based on custom logic. To create a custom summary, follow the steps below:
- Declare a DxGridSummaryItem object in the GroupSummary or TotalSummary template.
- Set the SummaryType property to
Custom
. Handle the Grid’s
CustomSummary
event to implement summary calculation algorithm.The
CustomSummary
event occurs multiple times as follows:- Once, before grid rows are processed. The event argument’s SummaryStage property returns
Start
. At this stage, you can initialize a summary value. - For each data row in the processed range. The SummaryStage property returns
Calculate
. At this stage, you can calculate a summary value. - Once, after grid rows are processed. The SummaryStage property returns
Finalize
. At this stage, you can finalize summary calculation.
- Once, before grid rows are processed. The event argument’s SummaryStage property returns
(Optional). If the summary value can change dynamically, call the RefreshSummary() method to refresh grid summary values.
- (Optional). Handle the CustomizeSummaryDisplayText event to change the summary’s display text.
<DxGrid @ref="Grid"
Data="@Data"
AllowSelectRowByClick="true"
SelectedDataItems="@SelectedDataItems"
SelectedDataItemsChanged="Grid_SelectedDataItemsChanged"
CustomSummary="Grid_CustomSummary"
CustomizeSummaryDisplayText="Grid_CustomizeSummaryDisplayText"
SizeMode="Params.SizeMode"
KeyboardNavigationEnabled="Params.KeyboardNavigationEnabled">
<Columns>
<DxGridSelectionColumn Width="60px"/>
<DxGridDataColumn FieldName="CompanyName" MinWidth="100" />
<DxGridDataColumn FieldName="City" Width="10%" />
<DxGridDataColumn FieldName="Region" Width="10%" />
<DxGridDataColumn FieldName="Country" Width="10%" />
<DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c" Width="10%" />
<DxGridDataColumn FieldName="Quantity" Width="10%" />
<DxGridDataColumn FieldName="Total"
UnboundType="GridUnboundColumnType.Decimal"
UnboundExpression="[UnitPrice] * [Quantity]"
DisplayFormat="c"
MinWidth="100"
Width="15%" />
</Columns>
<TotalSummary>
<DxGridSummaryItem SummaryType="GridSummaryItemType.Custom" Name="Custom" FieldName="Total" />
</TotalSummary>
</DxGrid>
@code {
@* ... *@
IGrid Grid { get; set; }
@* ... *@
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("Total");
break;
}
}
void Grid_CustomizeSummaryDisplayText(GridCustomizeSummaryDisplayTextEventArgs e) {
if(e.Item.Name == "Custom")
e.DisplayText = string.Format("Sum of Selected: {0:c}", e.Value);
}
void Grid_SelectedDataItemsChanged() {
Grid.RefreshSummary();
}
}
Limitations
Grid does not support custom summary when you use GridDevExtremeDataSource.
If you use Server Mode data source, the
CustomSummary
event fires only once. The SummaryStage property returnsFinalize
.
For more information about summaries in the Grid control, refer to the following topic: Summary in Blazor Grid.