aspnet-119616-components-card-view-concepts-data-shaping-and-manipulation-data-summaries-custom-aggregate-functions.md
Total summary provides five predefined aggregate functions. These functions allow you to calculate:
ASPxCardView includes the ASPxGridBase.CustomSummaryCalculate event, which enables you to implement custom aggregate functions or calculate summary values with a custom algorithm. Custom summaries allow you to do the following:
You can calculate a summary manually as follows:
The ASPxGridBase.CustomSummaryCalculate event fires for each card involved in summary calculation. The event is raised before and after card processing, so that you can initialize and finalize summary values as required.
Summary calculation consists of the following three stages.
Initialization
Calculation
Finalization
To determine the current stage, use the event parameter’s SummaryProcess property.
To skip the Calculation stage and calculate a custom summary during the Initialization or Finalization stage, set the event parameter’s TotalValueReady property to true at the Initialization stage. This automatically skips the Calculation stage and Finalization starts immediately.
The following example implements a custom summary calculation.
Note that in order to process selection changes on the server side, you can either set the ASPxGridBehaviorSettings.ProcessSelectionChangedOnServer property to true, or handle the ASPxClientCardView.SelectionChanged client event and call the client ASPxClientCardView.PerformCallback method.
int totalSum;
protected void ASPxCardView1_CustomSummaryCalculate(object sender, CustomSummaryEventArgs e)
{
if (e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Start)
totalSum = 0;
// Calculation.
if (e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Calculate)
if (ASPxCardView1.Selection.IsCardSelectedByKey(e.GetValue(ASPxCardView1.KeyFieldName)))
totalSum += Convert.ToInt32(e.FieldValue);
// Finalization.
if (e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Finalize)
e.TotalValue = totalSum;
}