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

ASPxPivotGrid.CustomSummary Event

Enables summary values to be calculated manually.

Namespace: DevExpress.Web.ASPxPivotGrid

Assembly: DevExpress.Web.ASPxPivotGrid.v19.1.dll

Declaration

public event PivotGridCustomSummaryEventHandler CustomSummary

Event Data

The CustomSummary event's data class is PivotGridCustomSummaryEventArgs. The following properties provide information specific to this event:

Property Description
ColumnField Gets the column field that corresponds to the current cell. Inherited from PivotGridCustomSummaryEventArgsBase<T>.
ColumnFieldValue Gets the value of the column field that corresponds to the current cell. Inherited from PivotGridCustomSummaryEventArgsBase<T>.
CustomValue Gets or sets a custom summary value. Inherited from PivotGridCustomSummaryEventArgsBase<T>.
DataField Gets the data field against which the summary is calculated. Inherited from PivotGridCustomSummaryEventArgsBase<T>.
FieldName Gets the name of the data field against which the summary is calculated. Inherited from PivotGridCustomSummaryEventArgsBase<T>.
RowField Gets the row field that corresponds to the current cell. Inherited from PivotGridCustomSummaryEventArgsBase<T>.
RowFieldValue Gets the value of the row field that corresponds to the current cell. Inherited from PivotGridCustomSummaryEventArgsBase<T>.
SummaryValue Gets an object that contains the values of the predefined summaries which are calculated for the current cell. Inherited from PivotGridCustomSummaryEventArgsBase<T>.

The event data class exposes the following methods:

Method Description
CreateDrillDownDataSource() Returns data records associated with the current cell. Inherited from PivotGridCustomSummaryEventArgsBase<T>.

Remarks

The ASPxPivotGrid calculates summaries against data fields. A field’s PivotGridFieldBase.SummaryType property specifies the type of summary function. The control automatically calculates all the predefined summary functions (see the PivotSummaryType topic for a list of the available functions) and it allows custom summaries to be calculated manually using the CustomSummary event.

To calculate a custom summary for a specific data field, set its PivotGridFieldBase.SummaryType property to PivotSummaryType.Custom. In this instance, the CustomSummary event fires for each cell that corresponds to this data field. Use the PivotGridCustomSummaryEventArgsBase<T>.DataField property to identify the data field.

To identify the kind of a processed cell, you can use the PivotGridCustomSummaryEventArgsBase<T>.ColumnField and PivotGridCustomSummaryEventArgsBase<T>.RowField properties.

  • If ColumnField or RowField is null, it means that the processed cell is a Grand Total.
  • If both ColumnField and RowField are last fields in the corresponding area, this means that this is an ordinary cell.
  • In other cases, this is a Total cell.

For example, you can handle the CustomSummary event to calculate custom summaries against multiple fields, particular records, etc. Use the PivotGridCustomSummaryEventArgsBase<T>.CreateDrillDownDataSource method to get a list of records that correspond to the processed cell. This list can then be traversed to calculate a custom summary. The custom summary value should be assigned to the PivotGridCustomSummaryEventArgsBase<T>.CustomValue property.

The ASPxPivotGrid calculates all the predefined summaries (AVERAGE, MIN, MAX, SUM, etc.) for each cell. The calculated summaries can be accessed using the PivotGridCustomSummaryEventArgsBase<T>.SummaryValue property and used in custom summary calculations.

Note

The CustomSummary is not supported in server and OLAP modes.

Example

The following example shows how to calculate a custom summary.Assume that the ASPxPivotGrid control is bound to an "Invoices" table, which contains invoices information (product name, extended price, salesperson, etc). A field that displays the ratio of units cost over $50 is to be added.In this example, a custom summary is calculated against the "Unit Price" field. Its PivotGridCustomTotalBase.SummaryType property is set to PivotSummaryType.Custom and the caption to "Percentage of units cost over $50". The PivotGridControl.CustomSummary event is handled to only count those records whose total sum exceeds $50. The ratio of these records to all the records is a custom summary value and, therefore, is assigned to the PivotGridCustomSummaryEventArgsBase.CustomValue parameter.

using System.Web.UI;
using DevExpress.Web.ASPxPivotGrid;
using DevExpress.XtraPivotGrid;

namespace ASPxPivotGrid_CustomSummary {
    public partial class _Default : Page {
        static int minSum = 500;
        protected void ASPxPivotGrid1_CustomSummary(object sender, 
                                                    PivotGridCustomSummaryEventArgs e) {
            if (e.DataField != fieldExtendedPrice) return;

            // A variable which counts the number of orders whose sum exceeds $500.
            int order500Count = 0;

            // Get the record set corresponding to the current cell.
            PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();

            // Iterate through the records and count the orders.
            for (int i = 0; i < ds.RowCount; i++) {
                PivotDrillDownDataRow row = ds[i];

                // Get the order's total sum.
                decimal orderSum = (decimal)row[fieldExtendedPrice];
                if (orderSum >= minSum) order500Count++;
            }

            // Calculate the percentage.
            if (ds.RowCount > 0) {
                e.CustomValue = (decimal)order500Count / ds.RowCount;
            }
        }
    }
}
See Also