Pivot Total Columns

Summary

  • AdapTable provides 3 Pivot Total Columns:
    • Pivot Grand Total
    • Pivot Column Total
    • Pivot Aggregation Total

AdapTable provides Pivot Total Columns for use in AG Grid pivoting.

These are special columns which allow users to analyze data through different levels of aggregation.

There are 3 different types of Pivot Total Columns available, all of which can be defined, customised and positioned before or after the associated pivot data.

ColumnDescription
Pivot Grand TotalProvides a summary view of all pivot data
Pivot Column TotalInserts subtotal columns for each Pivot Column Group
Pivot Aggregation TotalTotals each Pivot Result column value in each Pivot Column Group separately

Caution

Pivot Column Totals cannot be combined with Pivot Aggregation Total Columns in the same Layout

Hint

In addition, AdapTable provides Grand Total Rows which display the totals for all Aggregated Cells

Pivot Grand Total

Pivot Grand Total Columns provide a summary view of all pivot aggregation data.

One Pivot Grand Total Column is displayed for each Aggregation Column defined in the Pivot Layout, showing the total aggregation for that column.

Note

The Column calculates totals using the specified aggregation function for each column independently

Pivot Grand Totals
Fork
  • This example contains 2 Layouts which each contain aggregations for the Gold, Silver and Bronze columns
  • Both Layouts are configured to display a Pivot Grand Total Column, so that 3 are provided in total, one for each aggregation
  • The Grand Total Before Layout displays the Pivot Grand Totals before the Pivot Result Columns, and the Grand Total After shows it at the end

Pivot Column Total

Pivot Column Totals are subtotal columns inserted for each Pivot Column Group.

AdapTable calculates each group-specific total using a common aggregation function.

Caution

All Aggregation Columns must use the same aggFunc (e.g. sum )

Pivot Column Totals
Fork
  • Like the demo above, this example also includes 2 Layouts which each contain aggregations for the Gold, Silver and Bronze columns
  • Both Layouts are configured to display Pivot Column Totals - in one Layout the columns are placed at the start of each Group, and in the other Layout at the end
  • Note: a Pivot Column Total is displayed for each Pivot Column Grouping, e.g. for Athletics, Athletics/2000, Athletics/2004, Basketball, Basketball/2000 etc.

Pivot Aggregation Total

Pivot Aggregation Totals calculate and display totals for each Pivot Result Column within each Pivot Column Group independently.

The Pivot Aggregation Total Columns use column-specific aggregation functions.

Pivot Aggregation Totals can be configured in 2 ways:

  • per Layout
  • per specific Pivot Column groups

Per Layout Aggregation

Pivot Aggregation Totals can be configured so they are the same for each Pivot Result Column produced by the Aggregation.

Pivot Aggregation Totals Layout
Fork
  • Like the demos above, this example also includes 2 Layouts which all contain aggregations for the Gold, Silver and Bronze columns
  • Both Layouts display Pivot Aggregation Total Columns for the whole Column:
    • Aggregation Total Standard Layout shows Pivot Aggregation Totals for all 3 Aggregation Columns - Gold and Bronze before the Column and Silver after the Column
    • Aggregation Total Selective Layout shows Pivot Aggregation Totals for Gold (before) and Bronze (after) (but no Aggregation Total for Silver)

Per Pivot Column Aggregation

Pivot Aggregation Totals can also be configured on a per Pivot Result Column basis.

In other words, users can decide which Pivot Columns will show a Total (and the Column's position).

For example, to show Pivot Aggregation Total Columns only for gold with sport you can provide:

PivotColumns: ['sport', 'year'],
PivotAggregationColumns: [{
    ColumnId: 'gold',
    AggFunc: 'sum',
    Total: [{
        PivotColumnId: 'sport',
        ShowTotal: 'before'
    }]
}]
Pivot Aggregation Totals Pivot Column
Fork
  • This example has a Layout which contains aggregations for the Gold, Silver and Bronze columns - but with Pivot Aggregatation Totals configured on a per-Column basis:
    • Gold / Sport - before
    • Gold / Year - none
    • Silver / Sport - no Aggregation column configured (so no Pivot Total possible either)
    • Silver / Year - true (i.e. before)
    • Bronze / Sport - false
    • Bronze / Sport - after

Positioning

All 3 Pivot Total Types share the same ability to position the Column, dynamically generated by AdapTable, before or after the relevant pivot data.

They each use the PivotTotalPosition object which can receive 4 arguments:

ColumnPivot Grand TotalPivot Column TotalPivot Aggregation Total
beforeBefore all Pivot Result ColumnsBefore each Pivot Column GroupBefore each Aggregation
afterAfter all Pivot Result ColumnsAfter each Pivot Column GroupAfter each Aggregation
truesame as beforesame as beforesame as before
falseNot displayedNot displayedNot displayed

Formatting & Styling

All Pivot Total columns automatically inherit the Column Formatting & Styling of their source value columns.

Hint

However custom formats can be provided targeting specific Pivot Total Columns, overriding the default inheritance

Total Columns Formatting Inheritance
Fork
  • This example applies Column Styling to the Gold column as seen in the Standard Pivot Layout
  • But we also see this applied in the Pivot Totals Layout Layout which has PivotGrandTotal and PivotColumnTotal both set to true

Column Types

AdapTable provides a type property value for each Pivot Total.

This allows to to set the Column Scope for the Format to all Columns of a particular type.

These column types are available via the AdaptableColumnType as follows:

AdaptableColumnType ValuePivot Total ColumnValue for type property
PivotGrandTotalPivot Grand TotalpivotGrandTotal
ּPivotColumnTotalPivot Column TotalpivotColumnTotal ּ
ּPivotAggregationTotalPivot Aggregation TotalpivotAggregationTotal ּ
PivotAnyTotal[All 3 Pivot Total types]pivotAnyTotal

Find Out More

See the Developer Guide to using Column Types for further details

Deep Dive

Registering Column Types for use in the UI

Total Columns Formatting Column Types
Fork
  • In this example we provide Column Styling where we change the Back Colour for 3 Column Types:
    • PivotGrandTotal - light blue - as seen in both Pivot Aggregation Layout and Pivot Cols Layout
    • PivotColumnTotal - light green - as seen in Pivot Cols Layout
    • PivotAggregationTotal - pink - as seen in Pivot Aggregation Layout

Formatting Pivot Column Totals

AdapTable allows you to choose to format a Pivot Column Total based on its expanded / collapsed state.

This is done by leveraging 2 functionalities in AdapTable:

Formatting Pivot Column Totals
Fork
  • In this example we provide Column Styling for PivotColumnTotal (we change the Back Colour to light green)
  • However we set the ColumnGroupScope to "Collapsed" so the Style is only visible when the Group is Collapsed
Try It Out

Collapse a Pivot Column Total (e.g. 'Athletics') and see how the green Format Column style is rendered

Customising Total Column Headers

The Column Header (i.e. Caption) displayed for the Pivot Total Columns is also customisable.

This is done using the columnHeader property in Column Options which allows customisation on a per Column Type, or individual Column, basis if required.

Find Out More

Totals Columns Customising Header
Fork
  • In this example we customise headers for the Pivot Total Columns by providing an implementation for the columnHeader property in Column Options
  • We add 'PGT' to Pivot Grand Totals and 'PCT' to Pivot Column Totals (see Pivot Grand Totals Layout) and 'PAT' to Pivot Aggregation Totals (see Pivot Aggregation Totals Layout)
  • Note: We provided 2 Layouts because you cannot have Pivot Column Totals and Pivot Aggregation Totals in the same Layout

Updating Total Columns at Runtime

The Pivot Totals configuration can be updated at run-time in 2 ways:

Updating Pivot Total Columns
Fork