#Table Views
A table view shows your data as rows and columns, optionally grouped and
aggregated. Any view without pivotColumns is a table view.
This page builds on Views, which covers the column model:
available columns, column properties and defaults, and how columnOrder,
columnOverrides and columnVisibility lay out the columns of a view.
const view: AdaptableTableView = {
id: 'developers',
label: 'Developers',
columnOrder: ['firstName', 'lastName', 'preferredLanguage', 'salary'],
columnOverrides: { salary: { width: 160 } },
columnSorting: [{ columnId: 'salary', dir: 'desc' }],
};#Row grouping
A table view groups its rows through groupColumns — a record of synthetic
group columns, keyed by id. Each group column has a groupBy: the id of the
column to group by, or an array of ids. Columns with rowGroupable: false are
skipped.
Group columns are configured like regular columns — label, width, pinned
and every other overridable property — and positioned with columnOrder.
Group columns missing from columnOrder render first. Their ids don't
reference available columns; any id works, as long as it's unique in the view.
There are two ways to render the grouping:
-
One group column per field — several group columns, each grouping by a single column. Nesting follows the order in which the group columns appear in the view.
groupColumns: { 'language-group': { groupBy: 'preferredLanguage', label: 'Language' }, 'country-group': { groupBy: 'country', label: 'Country' }, }, -
One group column for all fields — a single group column whose
groupBylists several column ids, in nesting order.groupColumns: { group: { groupBy: ['preferredLanguage', 'country'], label: 'Language / Country' }, },
Don't mix the two: a group column that groups by several fields must be the only group column in the view.
Both views group by language, then country. The first renders a group column for each field; the second renders a single group column. Switch views from the picker.
Users change the grouping from the column menu (Group By …), the
Grouping page of the settings panel — which also switches between the two
rendering strategies — or Adaptable.UI.GroupingEditor. For custom UIs, the
useColumnGrouping composable exposes the same operations (setGrouping,
addGroupByColumn, removeGroupByColumn, setStrategy, …).
A few more group column settings:
field— binds the group column to a data field: non-group rows then show that field's value in the group column, like a regular column.- A view's
rowGroupsStatestores which groups are expanded or collapsed. It is reset when the grouping changes, since the old group keys no longer apply.
#View private entities
Besides the global entities, each view can carry privateEntities with the same
shape as globalEntities. Columns in privateEntities.availableColumns are
available to that view only — in its layout and in its column pickers — and the
view's private columnDefaults, dataTypeDefaults, columnTypeDefaults and
sortTypes are merged over the global ones.
The Compensation view defines two calculated columns, bonus and total,
in its private entities, plus its own column width default. The People view
can't use those columns — it only sees the global ones.
#Column sorting
A view's sorting lives in columnSorting — an array of columnId / dir
pairs, in priority order. dir is 'asc' or 'desc', and the column doesn't
have to be visible in the view.
columnSorting: [
{ columnId: 'preferredLanguage', dir: 'asc' },
{ columnId: 'salary', dir: 'desc' },
],By default users sort by several columns at once: clicking a header sorts by
that column, Cmd/Ctrl+clicking adds it to the current sort. Set
singleColumnSort: true on a view (or in view.viewDefaults) to restrict the
UI to one column at a time.
singleColumnSort only affects the UI — columnSorting can still hold several
entries when you set it in code.
The first view sorts by language, then by salary descending. The second view
has singleColumnSort — clicking a header replaces the current sort.
The Sorting page of the settings panel edits the sort and its priority; the
useColumnSorting composable does the same in code.
#Custom sort types
Columns sort according to their dataType. To sort a column differently,
define a sort type in globalEntities.sortTypes — a label and a compare(a, b)
function — and reference it from the column's sortType:
globalEntities: {
availableColumns: {
preferredLanguage: {
field: 'preferredLanguage',
dataType: 'text',
sortType: 'language-rank',
},
},
sortTypes: {
'language-rank': {
label: 'Language rank',
compare: (a, b) => LANGUAGE_ORDER.indexOf(a) - LANGUAGE_ORDER.indexOf(b),
},
},
},sortType is a column property, so it also works in columnDefaults,
columnTypeDefaults, dataTypeDefaults (to change the sort of a whole data
type) and in a view's columnOverrides.
The language column sorts by a fixed ranking — TypeScript, JavaScript, Python, Go, Rust, Java — instead of alphabetically.
#Column aggregations
When a view is grouped, group rows can show aggregated values. Set the
aggregation of a column either in its definition — it then applies in every
view — or in a view's columnOverrides, for that view only:
availableColumns: {
salary: { field: 'salary', dataType: 'number', aggregation: 'sum' },
},columnOverrides: {
salary: { aggregation: 'avg' },
country: { aggregation: 'distinct' },
},aggregation: false in a view's columnOverrides turns off an aggregation
inherited from the column definition. See Aggregations
for the built-in aggregations and for defining your own.
salary is summed in its column definition, and the first view adds a
distinct count of countries. The second view overrides salary to an average and
counts the rows through lastName.
The Aggregations page of the settings panel and the useColumnAggregations
composable edit the aggregations of the current view.
#Saving views
Everything users change in a table view — column sizes and order, visibility,
pinning, sorting, grouping, aggregations — is written back to the view in the
state, and persisted with it. See State for persistence and for
listening to changes, and useCurrentViewState
to read the current view from a component.