Displaying Column Aggregations
Summary
- Aggregations are supported via Layouts
- AdapTable provides a special Aggregation for Weighted Averages
AG Grid's Aggregation functionality displays aggregations of column values.
Note
- Aggregations are displayed by AG Grid in used when Grouped Rows
- By default, Aggregations display
sumof values, but many different aggregation types are available
AdapTable Layouts provide full support in for AG Grid Aggregations, including:
-
Ability to define ָAggregations in Initial Adaptable State - for both Table Layouts and Pivot Layouts
-
Automatic Persistence of Aggregations created at run-time into Layout section of Adaptable State, and then be dynamically re-applied when the Layout next loads
-
Two custom Aggregations for Weighted Averages and Only
-
Support for Grand Total Rows which display the totals for all cells in the Grid (and not a single Group)
Hint
- AdapTable additionally provides a very useful and powerful Row Summary feature
- This allows users to see aggregation information even when there is no Row Grouping
Aggregations in Column Header
By default AG Grid prefixes the type of the aggregation function (aka aggFunc) to the Column's header.
For instance adding sum to a Price column will result in a Column header of "(sum) Price".
AdapTable allows this to be overridden through the SuppressAggFuncInHeader property in each Layout.
Note
This override is per Layout in AdapTable and not applied globally
Caution
- There is an AG Grid GridOptions property called
suppressAggFuncInHeaderwhich does the same thing - The Layout's
SuppressAggFuncInHeaderproperty replaces this and is only place where this functionality can be set
- This example includes 2 Layouts - one Table (with Row Grouping) and one Pivot - each with 2
sumAggregations - onGithub Watchers&Github StarsColumns - We have set
SuppressAggFuncInHeaderto true so that in both Layouts you see just "Github Stars" instead of "(sum) Github Stars".
- Click the Custom Toolbar to show / hide AggFuncs in the Column Header (the buttons invoke the updateCurrentLayout function in Layout API)
Formatting & Styling Aggregations
AdapTable allows users to format and style AggFuncs in a grouped row, in exactly the same way as a data row.
Find Out More
See Formatting and Styling Aggregations for more information and demos
Defining Aggregations
Developer Guide
Defining a Layout with Aggregations
// Define a Layout with 3 Aggregations:
// open_pr_count (avg), github_watchers (sum) & github_stars (default aggFunc for col)
// Weighted Aggregation for examResult (using attendance as Weighted Column)
// Provide a GrandTotalRow at top of Grid
// Set Aggregation Columns to display without name of the aggFunc
const initialState: InitialState = {
Layout: {
CurrentLayout: 'Grouping Layout',
Layouts: [
{
Name: 'Grouping Layout',
TableColumns: ['github_stars', 'open_pr_count', 'github_watchers', 'examResult', 'attendance'],
RowGroupedColumns: ['license', 'language'],
TableAggregationColumns: [
{
ColumnId: 'open_pr_count',
AggFunc: 'avg'
},
{
ColumnId: 'github_watchers',
AggFunc: 'sum'
},
{
ColumnId: 'github_stars',
AggFunc: true
},
{
ColumnId: 'examResult',
AggFunc: {
type: 'weightedAverage',
weightedColumnId: 'attendance',
},
}],
GrandTotalRow: 'top',
SuppressAggFuncInHeader: true,
}],
},
}A Table Layout can define which Aggregations are available in Grouped Rows, using the TableAggregationColumns property.
The TableAggregationColumns object contains 2 items:
- a
ColumnId(string) - either an
aggFunc(e.g. sum) or true (uses defaultaggFunc)
You can supply Weighted Average Aggregations if needed.
In this case 2 properties must be provided to the definition:
type- always set to 'weightedAverage'weightedColumnId- column which provides the Weight
Set GrandTotalRow prop to display a Row providing Totals of all aggregations.
Options for the property are:
top- shows it at top of gridbottom- shows it at bottom of gridtrue- equivalent totopfalse- doesn't display it
Setting SuppressAggFuncInHeader to true hides the name of the aggFunc in the Column Header, e.g. it will show 'Open PRs' instead of 'sum(Open PRs)'