#Columns
Columns are defined in two layers:
- Column definitions describe what a column is — where its value comes
from, its data type, label, renderers and default behavior. You declare them
once, in
globalEntities.availableColumnsin the Adaptable state (or privately, in a single view). - Views decide how the columns are presented — which ones are shown, in
what order, and with which per-view tweaks (width, pinning, label, …) — via
columnOrder,columnOverridesandcolumnVisibility.
#Column definitions
globalEntities.availableColumns is an object keyed by column id. Every
column definition needs a dataType — one of 'text', 'number', 'date',
'boolean' or 'array' — and exactly one source for its value:
field— the name of a property in the row data.valueGetter— a function({ data }) => valuethat computes the value in JavaScript.expression— an AdaptableQL expression. This makes it a calculated column.
const defaultState: AdaptableUserState = {
globalEntities: {
availableColumns: {
firstName: { field: 'firstName', dataType: 'text' },
initials: {
dataType: 'text',
valueGetter: ({ data }) => `${data.firstName[0]}${data.lastName[0]}`,
},
monthlySalary: { dataType: 'number', expression: 'ROUND([salary] / 12, 0)' },
},
},
view: { currentViewId: 'default', views: [{ id: 'default', label: 'Developers' }] },
};The column definitions in globalEntities are available to every view. A
view without a columnOrder shows all of them, in definition order.
The column id (the key) is how the rest of the state refers to a column — in
columnOrder, sorting, styled cell scopes, and AdaptableQL expressions like
[salary]. It does not have to match the field.
firstName, lastName and salary are field columns, initials uses a
valueGetter, and monthlySalary is a calculated column with the expression
ROUND([salary] / 12, 0). The salary column also uses renderValue to
format the displayed value.
#Column properties
Besides dataType and the value source, a column definition accepts:
checkboxSelection— shows a selection checkbox in the column's cells.columnType— one or more column types (see Column types).editable— enables cell editing (off by default; calculated columns are never editable).exportable— whether the column is included in exports; a boolean or a function.filterable,filterType,filterValues,filterOperators— the column filter (off by default). See Column filters.label— the header text. When omitted, thefield(or the column id) is humanized:lastNamebecomesLast name.pinned— pins the column to the start of the grid.renderValue,renderGroupValue,renderHeader,components— custom rendering. These receive the Infinite Table render params plusadaptableColumnandview.resizable— whether the user can drag the column width.rowGroupable,pivotable,aggregatable,aggregation— grouping, pivoting and the aggregation shown in group rows.sortable,sortType— sorting, and which comparator to use.visible— whether the column is shown (defaults totrue).width,flex,minWidth,maxWidth— sizing. A column withflexshares the available space; otherwise it gets a fixedwidth(200px by default).
#Column defaults
Rather than repeating the same properties on every column, set defaults in
globalEntities:
columnDefaults— applied to every column.dataTypeDefaults— applied to every column of a data type, keyed by data type (number,text, …).columnTypeDefaults— applied to every column tagged with a column type, keyed by column type.
The layers are merged in this order, with later ones winning:
- built-in defaults
columnDefaultsdataTypeDefaults[column.dataType]columnTypeDefaultsfor each of the column's types, in array order- the column definition itself
- the view's
columnOverrides(andcolumnVisibilityfor visibility)
globalEntities: {
availableColumns: {
/* ... */
},
columnDefaults: { width: 170, editable: true },
dataTypeDefaults: {
number: { width: 120 },
},
columnTypeDefaults: {
identity: { pinned: true, editable: false, width: 130 },
},
},Don't mix flex and width across layers: when a column ends up with a flex
value, it wins over any width.
#Column types
columnType takes a string or an array of strings. Use column types to:
- give a group of columns a common set of properties, via
columnTypeDefaults— defining defaults for a type is optional; - tag columns, so other features can target them — for example a styled cell
scope with
columnTypes: ['currency'](see Styled cells).
Every column is editable and 170px wide (columnDefaults), number columns are
120px wide (dataTypeDefaults), and the identity columns — firstName and
lastName — are pinned and read-only (columnTypeDefaults). The salary
definition sets editable: false, which wins over the defaults. Double-click a
country cell to edit it.
#Columns in views
A table view picks and arranges the available columns:
columnOrder— the ordered column ids to show. It doubles as the inclusion list: columns not listed are not part of the view.columnOverrides— sparse, per-column overrides for this view only, keyed by column id:width,flex,pinned,label,editable,aggregation,visibleand more.columnVisibility— hidden columns ({ [columnId]: false }). Hidden columns keep their position incolumnOrder, and this map has the final say on visibility.includeColumns/excludeColumns— restrict which available columns the view (and its column editors) can use at all.
{
id: 'overview',
label: 'Overview',
columnOrder: ['firstName', 'lastName', 'country', 'salary'],
columnOverrides: {
firstName: { pinned: true },
salary: { label: 'Annual salary', width: 160 },
},
columnVisibility: { country: false },
},When users resize, pin, hide or reorder columns, Adaptable writes the change into these same properties of the current view. See Table views for sorting, grouping and group columns.
#Private columns
A view can also define its own columns in privateEntities.availableColumns.
Private columns are only available to that view; it can reference both
global and private columns. privateEntities mirrors globalEntities, so a
view can also have its own columnDefaults, columnTypeDefaults and
dataTypeDefaults, which win over the global ones.
The Overview view orders the columns, pins firstName, relabels and
resizes salary, and hides country. Switch to the With bonus view: it
defines a private bonus calculated column that the other view doesn't know
about.
#The checkbox column
Setting showCheckboxColumn: true on a multi-row selection adds a checkbox
column to the view:
{
id: 'default',
label: 'Developers',
selection: { mode: 'multi-row', showCheckboxColumn: true },
},The column has the id 'checkbox-column' (exported as CHECKBOX_COLUMN_ID) and
is a column of the view like the others: it is listed on the Columns settings
page, where you can reorder, hide, pin, size or remove it. It is first unless
columnOrder lists it, and columnOverrides['checkbox-column'] and
columnVisibility configure it; it is not pinned unless an override pins it:
{
id: 'placed',
label: 'Checkbox after the name',
selection: { mode: 'multi-row', showCheckboxColumn: true },
columnOrder: ['firstName', 'lastName', 'checkbox-column', 'country', 'salary'],
columnOverrides: {
'checkbox-column': { width: 60 },
},
},Removing the column from the view turns showCheckboxColumn off. To show the
checkbox in one of your own columns instead, see
Selection checkboxes.
#Editing columns in the UI
The Columns page of the settings panel lists the columns of the current table view. Drag a row to reorder it, use its checkbox to show or hide it, and use the row buttons to rename, size, pin or remove it.
Clicking a row opens the column in the inspector, which edits every property of the column for the current view:
- Display — the label.
- Layout — visibility, pinning, the size (the column default, a fixed width or a flex value) and the minimum and maximum width.
- Sorting & aggregation — the sort direction (with its priority when the view sorts by several columns) and the aggregation shown on group rows.
- Filter — the column filter, if the column has one, which you can pause or remove.
- What users can do — whether the column is sortable, resizable, editable, groupable, aggregatable and exportable.
- Selection — whether the column shows a row selection checkbox (views with multi-row selection only).
- Used by — the styled cells and flashing cells of the view and the alerts that target the column. Click one to edit it, or add a styled cell for the column.
The inspector writes to the current view only — columnOverrides, or the
groupColumns entry of a group column — so other views keep the column as
defined. A dot next to a property means the view sets it to something other
than the column definition (with column defaults
applied); its reset button restores the definition's value. Reset column
removes every change the view makes to the column, apart from its visibility
and position. Setting a property back to the definition's value also removes
it from columnOverrides.
When the panel is wide enough, the inspector sits beside the list; otherwise it takes the list's place, with a button to go back to all columns. Up and Down move through the list.
Edit Column in a column's header menu opens the Columns page with that
column in the inspector. In code, call
settingsPanelApi.showSettingsPanel('view/table/columns', { type: 'edit', id: columnId }).
#Column hooks
For custom column UIs, the following hooks read and change the columns of the
current view. They only need an Adaptable.Provider ancestor.
useVisibleColumns()— the visible columns of the current table view.useViewColumns()— all columns of the view (including hidden and group columns), the available columns not in the view, and setters:setColumnOrder,setColumnVisible,addColumn,removeColumn,patchColumn(writes tocolumnOverrides).useColumnSizing()—setColumnSizing(columnId, { width })or{ flex }; setting one clears the other.useColumnPinning()—setColumnPinned(columnId, pinned).useColumnLabels()—setColumnLabel(columnId, label)(writes thelabelofcolumnOverrides); an empty label ornullrestores the default.useColumnProperties()— what the inspector uses.getProperty(columnId, key)returns thevaluethe column uses in the view, theinheritedvalue from its definition, andoverridden, which istruewhen the view sets the property to another value.setProperty(columnId, key, value)writes the property for the view;null, or the inherited value, removes the override. UseresetColumn(columnId)to remove all of the view's changes to a column, andisColumnOverridden(columnId)to check whether there are any. The keys arelabel,pinned,width,flex,minWidth,maxWidth,sortable,resizable,editable,rowGroupable,aggregatable,exportable,aggregationandcheckboxSelection.
import { useViewColumns } from '@adaptabletools/datagrid-react';
function HideColumnButton({ columnId }: { columnId: string }) {
const { setColumnVisible } = useViewColumns();
return <button onClick={() => setColumnVisible(columnId, false)}>Hide</button>;
}See Hooks for the full list.