Adaptable Column
Summary
- AdapTable creates an
AdaptableColumnobject for every AG Grid Column each time the Application starts - AdapTable Columns are created from 3 sources:
- Every column defined in
columnDefsproperty of AG Grid GridOptions - Special Columns used in AdapTable - i.e. Action, Calculated and FreeText Columns
- Columns dynamically created by AG Grid (e.g. Row Grouped Columns, Pivot Columns, Tree Columns etc.)
- Every column defined in
- Many objects in Initial Adaptable State rely heavily on Columns and generally use the
columnIdproperty
When AdapTable is being initialised it dynamically creates a collection of AdaptableColumn objects.
There is one Adaptable Column for every column in the Grid, and they can be of 3 types:
-
Based on the
ColDefprovided in thecolumnDefsproperty of GridOptions -
Created for each Special Column provided to AdapTable (of which there are 3 types):
-
Matching columns that are dynamically created by AG Grid - these include:
Hint
See below for details on how AdapTable sets the properties of the AdapTable Column
AdapTable Column Properties
Adaptable Columns are defined using the AdaptableColumn object which contains a large number of properties.
These properties are evaluated by AdapTable when the Application starts.
Deep Dive
AdaptableColumn Object: Full Properties
However, these properties fall into 4 broad groups which makes them easier to reason about.
Identity Props
The "Identity Props" define who the Column is.
They are probably the most important, and frequently used, properties and include:
columnId
The columnId property is the primary way of referring to the Column, and what is generally used in Initial Adaptable State.
It is the stable key for the Column throughout AdapTable and maps directly to the AG Grid colId.
As AG Grid derives colId from the field property when one is not explicitly provided, the columnId will usually match the Column's field.
Hint
If you are holding an AG Grid ColDef and need the matching AdapTable Column, use getColumnForColDef rather than trying to work out the columnId yourself.
friendlyName
The friendlyName property sets how the Column is referred to throughout the AdapTable UI.
This includes the Expression Editor and all panels in the Settings Panel.
It is usually derived automatically from the headerName property in the AG Grid Column definition, but it can be provided explicitly in the columnFriendlyName function property in Column Options.
Hint
This is useful where you might have multiple columns with the same header (e.g. 'Price' or 'Bid') and you want to be able to differentiate between them in the UI
dataType
The dataType important property determines whether the Column is a number, string, date, boolean etc.
This influences many things in AdapTable e.g. what Column Filters are available.
AdapTable derives the value of the DataType, in the first instance by using the Cell Data Type of the AG Grid Column Definition if provided.
Note
- The Cell Data Type is assigned to the Column's AG Grid
ColDefdefinition using thecellDataTypeproperty - It is strongly advised that all AG Grid Col Definitions should include this property
columnTypes
The columnTypes property is based off the types property of the AG Grid Column Definition.
AdapTable will add additional values to this prop in some use cases (as detailed in this tutorial).
Deep Dive
How are the 'Identity' Properties set?
Find Out More
See Column Types: Scope for how to provide column types that are available when scoping objects
Capability flags
These properties define what a User is allowed to do with the Column: sortable, filterable, groupable, pivotable, aggregatable, queryable, exportable, moveable, hideable, readOnly.
Note
- Many of these are derived from functions you supply in Adaptable Options
- e.g.
exportablefromisColumnExportable,queryablefromisColumnQueryable
Column-kind flags
These properties define what sort of Column it is: isCalculatedColumn, isFreeTextColumn, isActionColumn, isPivotTotalColumn, isGeneratedRowGroupColumn, isGeneratedSelectionColumn, isGeneratedPivotResultColumn, isSparkline
Live grid-state
These properties define the Column's current state in the Grid: visible, pinned, width, flex, isGrouped, isFixed
Caution
- The Live grid-state properties reflect the state of the Column at the moment the object was retrieved
- If the Column is subsequently moved, pinned, or grouped etc, a previously retrieved
AdaptableColumnwill be stale
Hint
- Do not cache these values
- Re-fetch the Column via Column API (e.g.
getColumnWithColumnId) whenever you need the current state
Types of AdapTable Columns
It is worth dividing up AdapTable Columns into 3 groups.
Note
The type of the AdapTable Column also influences how AdapTable evaluates the associated properties
Regular Columns
Regular columns are those which are defined initially in AG Grid GridOptions object.
AdapTable will work out the values for that Column's properties in AdapTable Column in 2 ways:
- using the values provided in the AG Grid Column Definition
Note
Examples are field, groupable, movable, sortable - all based off similar properties in Grid Options
- reading some properties provided in Adaptable Options, for example:
exportable- derived from theisColumnExportableproperty in Export Optionsqueryable- derived fromisColumnQueryableproperty Expression Options
Special Columns
AdapTable can create 3 'Special Columns' which are not defined in Grid Options but through AdapTable itself:
In these cases AdapTable uses a combination of:
- properties provided in the object definitions in Initial Adaptable State
- sensible defaults for the Column (e.g. Action Columns have
readOnlyset to true)
Derived Columns
There are various use cases where AG Grid will create a create a Column that is not provided by the developer in ColumnDefs. These include:
Note
When this happens AdapTable will always create a matching Column, also provided dynamically
Using AdapTable Columns
Run-time users leverage AdapTable Columns continuously but indirectly through AG Grid.
The overwhelming majority of users of AdapTable will not need to be aware of the existence of AdapTable Columns.
Developers will frequently access AdapTable Columns since they are often contained in Context objects supplied to functions, and used elsewhere in AdapTable (e.g. in the Column Menu).
Important
Developers will never create AdapTable Columns as they are provided dynamically by AdapTable
Most commonly you retrieve a Column through the Column API using its columnId and then read its properties:
// get a single Column and inspect it
const priceColumn = adaptableApi.columnApi.getColumnWithColumnId('price');
if (priceColumn) {
console.log(priceColumn.friendlyName); // e.g. 'Bid Price'
console.log(priceColumn.dataType); // e.g. 'number'
console.log(priceColumn.queryable); // capability flag
}You can use the column-kind flags to work out what sort of Column you are dealing with:
const column = adaptableApi.columnApi.getColumnWithColumnId('rating');
if (column?.isCalculatedColumn) {
// handle Calculated Columns differently to regular Columns
}If you are working with AG Grid directly and have a ColDef (for example inside an AG Grid callback), you can get straight to the matching AdapTable Column:
// map an AG Grid ColDef to its AdapTable Column
const abColumn = adaptableApi.columnApi.getColumnForColDef(colDef);Reference
Column Options
The ColumnOptions section of Adaptable Options contains properties for managing Adaptable Columns.
This includes an option to show a warning if it cannot find a provided Column.
showMissingColumnsWarning
Default: trueBooleanColumn Options Properties
| Property | Type | Description | Default |
|---|---|---|---|
| addColumnGroupToColumnFriendlyName | boolean | Appends the name of the Column Group to a Column's Friendly Name | false |
| columnFriendlyName | (columnFriendlyNameContext:ColumnFriendlyNameContext) => string | undefined | Provide an alternative Friendly Name for a Column | undefined |
| columnHeader | (context:ColumnHeaderContext) => string | Provide a custom Header Name for a Table or Pivot Column | |
| columnTypes | TypeHint<string,AdaptableColumnTypeName>[] | ((context:ColumnTypesContext) => TypeHint<string,AdaptableColumnTypeName>[]) | Optional list of Column Types - used for Scope and creating Special Columns | Empty Array |
| showMissingColumnsWarning | boolean | Log warning to console if AdapTable cannot find a column | true |
Column API
AdapTable provides the Column API class in Adaptable API to enable programmatic access to all the AdapTable Columns which have been created.
This includes a plethora of methods giving full access to the full range of properties in each Column:
| Method | Returns | Description |
|---|---|---|
| addColumnsToSelection(columnIds) | void | Adds (highlights) a group of Columns to any existing selection |
| addColumnToSelection(columnId) | void | Adds (highlights) a Column to any existing selection |
| autosizeAllColumns() | void | Autosizes all Columns in the Grid |
| autosizeColumn(columnId) | void | AutoSizes a Column |
| autosizeColumns(columnIds) | void | Autosizes given Columns |
| doesColumnExist(columnId) | boolean | Checks if Column has already been created |
| getAggregatableColumns() | AdaptableColumn[] | Returns all Aggregatable Columns |
| getAGGridColDefForColumnId(columnId) | ColDef | ColGroupDef | Returns AG Grid ColDef for a given ColumnId |
| getAGGridColumnForColumnId(columnId) | Column | Returns the AG Grid Column for a given ColumnId |
| getArrayColumns() | AdaptableColumn[] | Returns all array columns (number, tuple-number, object-number & text) |
| getBooleanColumns() | AdaptableColumn[] | Returns all boolean Columns |
| getColumnDataTypeForColumnId(columnId) | AdaptableColumnDataType | undefined | Returns Data Type for the Column with given ColumnId |
| getColumnIdForFriendlyName(friendlyName) | string | Retrieves ColumnId for Column with given Friendly Name |
| getColumnIdsForFriendlyNames(friendlyNames) | string[] | Retrieves ColumnIds for Columns with given Friendly Names |
| getColumns() | AdaptableColumn[] | Returns all Columns available (including hidden, special) |
| getColumnsByColumnType(columnType) | AdaptableColumn[] | Returns all columns of a given columnType |
| getColumnSummaryForColumnId(columnId) | AdaptableColumnSummary | Gets summary info for a column including filters and unique values |
| getColumnsWithColumnIds(columnIds) | AdaptableColumn[] | Retrieves Adaptable Columns with given ColumnIds |
| getColumnsWithDataType(dataType) | AdaptableColumn[] | Returns all Columns that have given DataType |
| getColumnsWithFriendlyNames(friendlyNames) | AdaptableColumn[] | Retrieves Adaptable Columns with given Friendly names |
| getColumnTypes() | string[] | Returns available columns types defined under columnOptions.columnTypes |
| getColumnWithColumnId(columnId, logWarning) | AdaptableColumn | undefined | Retrieves AdapTable Column with given ColumnId |
| getColumnWithFriendlyName(columnName, logWarning) | AdaptableColumn | Retrieves AdapTable Column with given Friendly name |
| getDateColumns() | AdaptableColumn[] | Returns all Date Columns |
| getDefaultAggFunc(columnId) | string | Returns the default Aggregation Function for a Column |
| getExportableColumns() | AdaptableColumn[] | Returns all Exportable Columns |
| getFilterableColumns() | AdaptableColumn[] | Returns all Sortable Columns |
| getFriendlyNameForColumnId(columnId, layout) | string | Retrieves Friendly Name of Column with given ColumnId |
| getFriendlyNamesForColumnIds(columnIds) | string[] | Retrieves Friendly Names for given ColumnIds |
| getGroupableColumns() | AdaptableColumn[] | Returns all Groupable Columns |
| getNonSpecialColumns() | AdaptableColumn[] | Returns all UI available columns excluding Action, FreeText and Calculated Columns |
| getNumberArrayColumns() | AdaptableColumn[] | Returns all number-array columns |
| getNumericArrayColumns() | AdaptableColumn[] | Returns all numeric array columns (number, tuple-number, object-number) |
| getNumericColumns() | AdaptableColumn[] | Returns all numeric Columns |
| getObjectNumberArrayColumns() | AdaptableColumn[] | Returns all object-number-array columns e.g. [x:1,y:2,x:3,y:4] |
| getPivotableColumns() | AdaptableColumn[] | Returns all Pivotable Columns |
| getPrimaryKeyColumn() | AdaptableColumn | undefined | Retrieves current Primary Key Column in AdapTable. It may be undefined if the primary key is auto-generated, or it is NOT mapped to a column. |
| getQueryableColumns() | AdaptableColumn[] | Returns all Queryable Columns |
| getRowGroupedColumns() | AdaptableColumn[] | Returns all columns currently Row Grouped |
| getSortableColumns() | AdaptableColumn[] | Returns all Sortable Columns |
| getSpecialColumns() | AdaptableColumn[] | Returns any Action, FreeText and Calculated Columns |
| getTextArrayColumns() | AdaptableColumn[] | Returns all string array Columns |
| getTextColumns() | AdaptableColumn[] | Returns all Text Columns |
| getTupleNumberArrayColumns() | AdaptableColumn[] | Returns all tuple-number-array columns e.g. [[1,2],[3,4]] |
| getUIAvailableColumns() | AdaptableColumn[] | Returns all Columns that can be displayed in UI (excludes always hidden cols) |
| getUIHiddenColumns() | AdaptableColumn[] | Returns Columns that are always hidden in UI (but available for Expressions) |
| getVisibleColumns() | AdaptableColumn[] | Returns all visible Columns |
| hasArrayDataType(columnId) | boolean | Checks if the Column with the given columnId has any Array-like DataType (TextArray,NumberArray,TupleNumberArray or ObjectNumberArray) |
| hasBooleanDataType(columnId) | boolean | Checks if the Column with the given columnId has DataType Boolean |
| hasColumnType(columnIdentifier, columnType) | boolean | Checks if the Column with given Column Identifier (columnId or ColDef) has a specific Column Type |
| hasDateDataType(columnId) | boolean | Checks if the Column with the given columnId has DataType Date |
| hasNumberDataType(columnId) | boolean | Checks if the Column with the given columnId has DataType Number |
| hasNumericArrayDataType(columnId) | boolean | Checks if the Column with the given columnId has an Numeric Array-like DataType (NumberArray,TupleNumberArray or ObjectNumberArray) |
| hasTextArrayDataType(columnId) | boolean | Checks if the Column with the given columnId has a Text Array-like DataType (TextArray) |
| hideColumn(columnId) | void | Hides a Column from Grid |
| isActionColumn(columnId) | boolean | Checks if Column with given ColumnId is an Action Column |
| isAgGridGeneratedColumn(columnId) | boolean | Whether column is auto generated by AG Grid (for selection, grouping, pivoting etc) |
| isAutoRowGroupColumn(columnId) | boolean | Checks if Column with given ColumnId is a row-group Column automatically generated by AG Grid |
| isAutoRowGroupColumnForMulti(columnId) | boolean | Checks if Column with given ColumnId is a row-group Column automatically generated by AG Grid, for row-grouping with group display type = 'multi' |
| isAutoRowGroupColumnForSingle(columnId) | boolean | Checks if Column with given ColumnId is a row-group Column automatically generated by AG Grid, for row-grouping with group display type = 'single' |
| isCalculatedColumn(columnId) | boolean | Checks if Column with given ColumnId is a Calculated Column |
| isColumnInGrid(columnId) | boolean | Returns true if the given Column exists in the Grid |
| isFdc3Column(columnId) | boolean | Checks if Column with given ColumnId is a FDC3 Column |
| isFreeTextColumn(columnId) | boolean | Checks if Column with given ColumnId is a Free Text Column |
| isPivotAggColumnWithNoPivotColumns(columnId) | boolean | Checks if Column with given ColumnId is a pivot aggregation column in a pivot layout with no pivot columns. When PivotColumns is empty, aggregation columns keep their original IDs instead of getting a 'pivot_' prefix. |
| isPivotResultColumn(columnId) | boolean | Checks if Column with given ColumnId is a pivot Column automatically generated by AG Grid |
| isSelectionColumn(columnId) | boolean | Checks if Column with given ColumnId is a Selection (Checkbox) Column automatically generated by AG Grid |
| isSpecialColumn(columnId) | boolean | Checks if Column with given ColumnId is a Special (i.e. calculated, freetext or action) Column |
| openColumnInfoSettingsPanel() | void | Opens Settings Panel with Column Info section selected and visible |
| selectAllColumns() | void | Selects all Columns |
| selectColumn(columnId) | void | Selects (highlights) a Column |
| selectColumns(columnIds) | void | Selects (highlights) group of Columns |
| setColumnCaption(columnId, caption) | void | Sets a new Caption / Header for a Column (only for current Layout) |
| showColumn(columnId) | void | Makes a Column visible |