Formatting Pivot Layouts
Summary
- All the different types of Columns used when pivoting in AG Grid can be formatted and styled by AdapTable:
- Aggregation Columns
- Pivot Result Columns
- Pivot Column Groups
- Pivot Row Grouped Columns
- Pivot Total Columns
- It is also possible to exclude pivoting from a given Style or Display Format
AdapTable ensures that Column Formatting and Styling work automatically when AG Grid pivoting is applied.
Formatting is applied for all the different types of Columns created when Pivoting.
Pivot Aggregation Columns
Providing Formatting to an Aggregated Column will style not only that column but also each associated Pivot Result Column that is created for it.
For example, if we provide a Format for a "Price" Column, that will be applied each time Price is displayed in the Grid as a Pivot Result Column (potentially multiple times based on the Pivoting applied).
- This demo shows Format Columns in Pivoting at its most basic. We apply 3 Format Columns definitions (2 with conditions):
- A Predicate Conditional Style to render cells in the
Open Issuescolumn red with white font where they > 35 - An Expression Conditional Style to render cells in the
GitHub Starscolumn yellow with brown font where they > 9,000 - A Light Blue Italic and Right Alignment Formatting Style for the
GitHub Watcherscolumn
- A Predicate Conditional Style to render cells in the
- We add 3 Layouts and both Formats are fully applied in all of them
Pivot Aggregation Layout- which has Pivot Aggregations -Github StarsandGithub Watchers- but no Pivot Columns (and so no Pivot Result Columns)Pivot Cols Layout- we pivot on License which creates 3 sets of Pivot Results Columns - and the formats are applied accordinglyTable Layout- a standard Table Layout which displays the same Column Formats
- Switch from the Standard to the Pivot Layout and see that the Format Columns are still applied
- Note that the Standard Layout includes 3 Format Columns, while the Pivot Layout has 2
Pivot Result Columns
Pivot Result Columns can individually be provided with specific, bespoke, Column Formatting.
This is different to the example above where formatting applied on an aggregation column, automatically included all Pivot Result Columns.
In order to do this, you will need to know the autogenerated id of the Column created by AG Grid.
Note
In practice run-time users create Format Columns in the UI on specific columns which are then persisted in the Layout
- In this example we have created 2 Format Columns on Pivot Result Columns in the Layout Definition (both using AG Grid's autogenerated
ColumnId)pivot_language_HTML_github_watchershas a Number Display Format with Prefix and Integer Digitspivot_language_JavaScript_github_starshas a Column Formatting Style applied
- For this reason, unlike the demo above, the Format Columns can be seen in
Pivot Cols Layout(but notPivot Aggregation Layout)
Pivot Columns Groups
It is not possible to Format a specific pivot column group by name.
In other words you cannot set Scope to a Column Group.
Instead, you need to create a Format Column which includes each of the Pivot Result Columns in the Group.
Pivot Row Grouped Columns
It is also possible to Format the Pivot Row Grouped Column - the column created when row grouping in Pivoting.
The way to do this is to set the Column Scope of the Format Column to be ‘ag-Grid-AutoColumn’.
- We provide a style for the Grouped column of white font on brown background.
Click the "Update Layout" button to change the Row Grouped Column in the Layout and note that the Format Style is unchanged
Pivot Total Columns
The specially generated Pivot Total Columns can also be formatted.
Find Out More
See Formatting Pivot Total Columns for detailed instructions
Excluding Pivoting
By default all relevant Formatting will appear in Pivot Layouts.
It is possible to leverage, the ExcludeGroupRows option in the Format Column's RowScope property to exclude Pivot Layouts from a particular Format or Stlye.
Hint
Set ExcludeGroupRows to true in the Format Column's RowScope property to exclude Pivot Layouts
- This demo provides 2 Format Columns that we see in the Pivot Layout - on
GitHub StarsandGitHub Watcherscolumns - However there is a 3rd Format Column (that sets
Open Issuesto Red) but as this hasExcludeGroupRowsset to true it does not appear in the Pivot Layout
- Switch from the Pivot to the Table Layout and see the Format Column for the
Open Issuescolumn