Skip to main content

PivotGridCustomTotal Class

Represents a custom total which can be calculated for an outer column field or row field.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.XtraPivotGrid.v24.1.dll

NuGet Package: DevExpress.Win.PivotGrid

Declaration

public class PivotGridCustomTotal :
    PivotGridCustomTotalBase

Remarks

The PivotGrid control supports automatic and custom Totals. An automatic total is calculated against a data field using a summary function which is determined by the field’s PivotGridFieldBase.SummaryType property.

A custom total allows you to calculate a total using a different summary function type. Moreover it’s possible to calculate multiple custom totals for a single data field.

Totals are displayed as additional rows or columns for each value in an outer column field or row field. To display custom totals for a column/row field, do the following:

When a sequence of operations is performed each of which affects the control’s appearance, the PivotGrid control updates itself after each such operation. To prevent excessive updates you should enclose the code within calls to the PivotGridControl.BeginUpdate and PivotGridControl.EndUpdate methods. For instance, when setting custom totals for a field via code you can enclose the code within the BeginUpdate and EndUpdate method calls. In this case, the control will be updated only once - by the EndUpdate method.

Example

In the following example, four custom totals are added for a ‘Category Name’ row field. They will calculate the total Average, Sum, Min and Max values against the currently displayed data field.

The result is shown below.

PivotGridField_CustomTotals_Ex

using DevExpress.Data.PivotGrid;
using DevExpress.XtraPivotGrid;

// Get a reference to the CategoryName field.
PivotGridField field = pivotGridControl1.Fields["CategoryName"];
pivotGridControl1.BeginUpdate();
try {
   // Clear the custom total collection.
   field.CustomTotals.Clear();
   // Add four items to the custom total collection to calculate the Average, 
   // Sum, Max and Min summaries.
   field.CustomTotals.Add(PivotSummaryType.Average);
   field.CustomTotals.Add(PivotSummaryType.Sum);
   field.CustomTotals.Add(PivotSummaryType.Max);
   field.CustomTotals.Add(PivotSummaryType.Min);
   // Make the custom totals visible for this field.
   field.TotalsVisibility = PivotTotalsVisibility.CustomTotals; 
}
finally {
   pivotGridControl1.EndUpdate();
}

Inheritance

Object
PivotGridCustomTotalBase
PivotGridCustomTotal
See Also