Adaptable Column

Summary

  • AdapTable creates an AdaptableColumn object for every AG Grid Column each time the Application starts
  • AdapTable Columns are created from 3 sources:
    • Every column defined in columnDefs property 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.)
  • Many objects in Initial Adaptable State rely heavily on Columns and generally use the columnId property

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:

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 ColDef definition using the cellDataType property
  • 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. exportable from isColumnExportable, queryable from isColumnQueryable

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 AdaptableColumn will be stale

Hint

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:

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 readOnly set 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: true
Boolean
Show a Warning when Columns are Missing

Column Options Properties

PropertyTypeDescriptionDefault
addColumnGroupToColumnFriendlyNamebooleanAppends the name of the Column Group to a Column's Friendly Namefalse
columnFriendlyName(columnFriendlyNameContext:ColumnFriendlyNameContext) => string | undefinedProvide an alternative Friendly Name for a Columnundefined
columnHeader(context:ColumnHeaderContext) => stringProvide a custom Header Name for a Table or Pivot Column
columnTypesTypeHint<string,AdaptableColumnTypeName>[] | ((context:ColumnTypesContext) => TypeHint<string,AdaptableColumnTypeName>[])Optional list of Column Types - used for Scope and creating Special ColumnsEmpty Array
showMissingColumnsWarningbooleanLog warning to console if AdapTable cannot find a columntrue

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:

MethodReturnsDescription
addColumnsToSelection(columnIds)voidAdds (highlights) a group of Columns to any existing selection
addColumnToSelection(columnId)voidAdds (highlights) a Column to any existing selection
autosizeAllColumns()voidAutosizes all Columns in the Grid
autosizeColumn(columnId)voidAutoSizes a Column
autosizeColumns(columnIds)voidAutosizes given Columns
doesColumnExist(columnId)booleanChecks if Column has already been created
getAggregatableColumns()AdaptableColumn[]Returns all Aggregatable Columns
getAGGridColDefForColumnId(columnId)ColDef | ColGroupDefReturns AG Grid ColDef for a given ColumnId
getAGGridColumnForColumnId(columnId)ColumnReturns 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 | undefinedReturns Data Type for the Column with given ColumnId
getColumnIdForFriendlyName(friendlyName)stringRetrieves 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)AdaptableColumnSummaryGets 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 | undefinedRetrieves AdapTable Column with given ColumnId
getColumnWithFriendlyName(columnName, logWarning)AdaptableColumnRetrieves AdapTable Column with given Friendly name
getDateColumns()AdaptableColumn[]Returns all Date Columns
getDefaultAggFunc(columnId)stringReturns the default Aggregation Function for a Column
getExportableColumns()AdaptableColumn[]Returns all Exportable Columns
getFilterableColumns()AdaptableColumn[]Returns all Sortable Columns
getFriendlyNameForColumnId(columnId, layout)stringRetrieves 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 | undefinedRetrieves 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)booleanChecks if the Column with the given columnId has any Array-like DataType (TextArray,NumberArray,TupleNumberArray or ObjectNumberArray)
hasBooleanDataType(columnId)booleanChecks if the Column with the given columnId has DataType Boolean
hasColumnType(columnIdentifier, columnType)booleanChecks if the Column with given Column Identifier (columnId or ColDef) has a specific Column Type
hasDateDataType(columnId)booleanChecks if the Column with the given columnId has DataType Date
hasNumberDataType(columnId)booleanChecks if the Column with the given columnId has DataType Number
hasNumericArrayDataType(columnId)booleanChecks if the Column with the given columnId has an Numeric Array-like DataType (NumberArray,TupleNumberArray or ObjectNumberArray)
hasTextArrayDataType(columnId)booleanChecks if the Column with the given columnId has a Text Array-like DataType (TextArray)
hideColumn(columnId)voidHides a Column from Grid
isActionColumn(columnId)booleanChecks if Column with given ColumnId is an Action Column
isAgGridGeneratedColumn(columnId)booleanWhether column is auto generated by AG Grid (for selection, grouping, pivoting etc)
isAutoRowGroupColumn(columnId)booleanChecks if Column with given ColumnId is a row-group Column automatically generated by AG Grid
isAutoRowGroupColumnForMulti(columnId)booleanChecks 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)booleanChecks 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)booleanChecks if Column with given ColumnId is a Calculated Column
isColumnInGrid(columnId)booleanReturns true if the given Column exists in the Grid
isFdc3Column(columnId)booleanChecks if Column with given ColumnId is a FDC3 Column
isFreeTextColumn(columnId)booleanChecks if Column with given ColumnId is a Free Text Column
isPivotAggColumnWithNoPivotColumns(columnId)booleanChecks 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)booleanChecks if Column with given ColumnId is a pivot Column automatically generated by AG Grid
isSelectionColumn(columnId)booleanChecks if Column with given ColumnId is a Selection (Checkbox) Column automatically generated by AG Grid
isSpecialColumn(columnId)booleanChecks if Column with given ColumnId is a Special (i.e. calculated, freetext or action) Column
openColumnInfoSettingsPanel()voidOpens Settings Panel with Column Info section selected and visible
selectAllColumns()voidSelects all Columns
selectColumn(columnId)voidSelects (highlights) a Column
selectColumns(columnIds)voidSelects (highlights) group of Columns
setColumnCaption(columnId, caption)voidSets a new Caption / Header for a Column (only for current Layout)
showColumn(columnId)voidMakes a Column visible