Providing Column Types
Summary
- Column Types are provided by Developers using the
typeproperty in the AG Grid Column Def - They are leveraged by AdapTable for:
- Scope — treat all Columns that share a type as a group (e.g. a Format Column)
- Special Columns — Calculated, FreeText and Action Columns, so AG Grid properties can be applied
- Hidden Columns — never visible in the Grid
- Pivot Total Columns
- FDC3 Columns
Column Types are supplied via the type property in an AG Grid Column Schema definition.
Hint
- The
typeproperty accepts an array as well as a single value - This allows developers to provide their own types as well as those which AdapTable and / or AG Grid expect
The most common use cases for Column Types in AdapTable are Scope, and the AdapTable-recognised types listed below.
Column Type Scope
Column Types can be used as an option when defining Scope.
Note
- The commonly used
ColumnScopeobject sets which Columns are to be included in an AdapTable Object - You set one Scope for multiple columns when creating Format Columns, Alerts, Flashing Cells and other objects
All columns containing the specified Column Type will be dynamically included in the Object's Scope.
Caution
- Column Types are not automatically available for AdapTable run-time users in the UI and associated wizards
- Use the
columnTypesproperty in Column Options to specify which of the supplied Column Types are listed
columnTypes
Default: undefinedstring[]- This demo showcases how to use Column Type Scope, through 3 Format Columns:
- The 2 Columns with a type of
github(i.e.Github Watchers&Github Stars) have a style of bold and centre-aligned - The 4 Columns with a type of
issue-pr(i.e.Open Issues,Closed Issues,Open PRs&Closed PRs) have a style of black font on blue background - The 2 Calculated Columns (and therefore with a type of
calculatedColumn-githubPopularity&totalStars) have a style of pink font and bold
- The 2 Columns with a type of
- The 3 types have also been provided in the
columnTypesproperty in Column Options so they can be accessed in the UI
AdapTable Column Types
AdapTable also recognises these built-in Column Types:
- Special Columns — Calculated, FreeText and Action Columns
- Pivot Total Columns — Pivot Totalling
- Hidden Columns — so they are not visible in the UI
- FDC3 Columns — FDC3
There are 9 column type values provided by AdapTable:
Hint
- AdapTable helps developers to configure the correct
typeproperty via Intellisense - This is done via the
AdaptableColumnTypeobject enabling, for example:
Scope: {
ColumnTypes: [AdaptableColumnType.CalculatedColumn] // instead of 'calculatedColumn'
},| String Equivalent | AdaptableColumnType Value |
|---|---|
actionColumn | ActionColumn |
calculatedColumn | CalculatedColumn |
fdc3Column | Fdc3Column |
freeTextColumn | FreeTextColumn |
hiddenColumn | HiddenColumn |
pivotAnyTotal | PivotAnyTotal |
pivotGrandTotal | PivotGrandTotal |
pivotColumnTotal | PivotColumnTotal |
pivotAggregationTotal | PivotAggregationTotal |
Special Columns
The most common use case for using Column Types in AdapTable is when configuring Special Columns:
Column Types are used here in 2 separate use cases:
- updating AG Grid Definitions
- providing additional column properties
AG Grid Definitions
Sometimes the developer might wish to refer to an AdapTable Special Column when creating Column Schema Definitions in AG Grid Grid Options.
Hint
- This can be useful if you want to place the Column in a Column Group
- Or if you want to add an AG Grid specific column definition property (e.g. a custom Tooltip component)
AG Grid Columns which will also serve as Special Columns are marked by configuring the types property of the Column Definition as follows:
| Special Column | Value for type property |
|---|---|
| Action Columns | actionColumn |
| Calculated Columns | calculatedColumn |
| FreeText Columns | freeTextColumn |
Note
- By default, AdapTable creates a new AG Grid column for each Special Column it encounters
- But in this scenario, it will update (patch) the AG Grid column with extra properties as required
Developer Guide
Defining Special Columns in AG Grid
There are 3 main steps you must follow in order to wire up AdapTable Special Columns in AG Grid:
export const columnDefs: (ColDef | ColGroupDef)[] = [
{
groupId: 'demoColGroup',
headerName: 'Special Columns',
children: [
{
// Create a Calculated Column
colId: 'subscribersRatio', // has to be same Id as in InitialState
cellDataType: 'number',
type: [AdaptableColumnType.CalculatedColumn, 'number-cell'],
// add a tooltip if required
tooltip: (params: ITooltipParams) => params.data,
tooltipComponent: CustomTooltip,
},
{
// Create a Free Text Column
colId: 'comments', // has to be same Id as in InitialState
cellDataType: 'text',
type: AdaptableColumnType.FreeTextColumn,
headerTooltip: 'Sometimes high, sometimes low',
},
],
},
];Use a full Column Definition as normal.
Add the ColDef to a Column Group if required.
Provide any components (e.g. Tooltip) as needed.
Caution
The colId value should be the same as that used for ColumnId in the Special Column definition
export const columnDefs: (ColDef | ColGroupDef)[] = [
{
groupId: 'demoColGroup',
headerName: 'Special Columns',
children: [
{
// Create a Calculated Column
colId: 'subscribersRatio', // has to be same Id as in InitialState
cellDataType: 'number',
type: [AdaptableColumnType.CalculatedColumn, 'number-cell'],
// add a tooltip if required
tooltip: (params: ITooltipParams) => params.data,
tooltipComponent: CustomTooltip,
},
{
// Create a Free Text Column
colId: 'comments',
cellDataType: 'text',
type: AdaptableColumnType.FreeTextColumn,
headerTooltip: 'Sometimes high, sometimes low',
},
],
},
];Make sure to add correct value to the type property. This should be:
calculatedColumn(orAdaptableColumnType.CalculatedColumn) — Calculated ColumnsfreeTextColumn(orAdaptableColumnType.FreeTextColumn) — FreeText ColumnsactionColumn(orAdaptableColumnType.ActionColumn) — Action Columns
CalculatedColumn: {
CalculatedColumns: [
{
FriendlyName: 'Subscribers Ratio',
ColumnId: 'subscribersRatio',
Expression: '[github_stars] / [github_watchers]',
CalculatedColumnSettings: {
DataType: 'number',
},
},
],
},
FreeTextColumn: {
FreeTextColumns: [
{
ColumnId: 'comments',
FreeTextColumnSettings: {
DataType: 'text',
},
},
],
},Define the Special Columns normally.
AdapTable will then automatically wire up the columns to the existing AG Grid columns.
This will be done in place of the usual practice which is to create a new AG Grid column.
- This demo shows 2 Special Columns that have been predefined in AG Grid:
- Calculated Column -
Subscribers Ratio - Free Text Column -
Comments
- Calculated Column -
- Both Columns have been predefined in AG Grid with these features:
- Placed in a Column Group (called Special Columns)
- A (cell) Tooltip has been added to the
Subscribers Ratiocolumn - A Header Tooltip has been added to the
Commentscolumn
- Both Columns have been created in Initial Adaptable State - using same value for AG Grid
colIdand AdapTableColumnId
Special Column Properties
AdapTable provides a large set of property options for Calculated and FreeText Columns (e.g. Filterable, Groupable etc.)
But sometimes developers will want to add additional properties.
This is achieved by supplying the Column Types in AG Grid Column Definitions, which they (and end users) can then attach to the Special Column.
Hint
This is particularly useful when you have defined bespoke AG Grid Column Types and you want to extend them to columns created at run-time in AdapTable.
The list of additional column type options to show to the run-time user is also defined (like with Scope - see above) in the columnTypes property in Column Options.
Pivot Total Columns
Another use case for using Column Types in AdapTable is when formatting Pivot Total Columns.
AdapTable provides 3 types of Pivot Total Columns each of which is given its own type property value:
| Pivot Total Column | Value for type property | AdaptableColumnType Value |
|---|---|---|
| Pivot Grand Total | pivotGrandTotal | ּּPivotGrandTotal |
| Pivot Column Total | pivotColumnTotal | ּּPivotColumnTotal |
| Pivot Aggregation Total | pivotAggregationTotal | ּּPivotAggregationTotal |
Note
- There is also a
PivotAnyTotalcolumn type available (string value ispivotAnyTotal) - This can be used to display all of the 3 Total Column types, particularly useful when formatting and styling
Find Out More
See Creating Pivot Total Columns for more information
Hidden Columns
A further use case for using Column Types in AdapTable is when hiding a Column altogether.
This can be done by setting the column type to hiddenColumn.
Columns marked with this type will not be:
- rendered in the Grid
- available in the Layout Wizard Editor
- listed in the Columns Tool Panel
However they will be available in the Expression Editor and Query Builder in order to use it to create Expressions.
Find Out More
See Hiding Columns in AdapTable for more details and a demo
FDC3 Columns
FDC3 columns use the fdc3Column type (AdaptableColumnType.Fdc3Column).
Find Out More
See FDC3 Data Mappings for how those columns are wired to FDC3 types