Adaptable

#Views

A view is everything the grid shows at a given time: which columns, in what order, how wide and where pinned; the sorting, row grouping, pivoting and aggregations; the filters; the selection and keyboard navigation; and which styled cells, flashing cells and custom sorts are active.

Views live in the state, so users can change them at runtime and those changes are persisted like any other state. The getting started page shows a first grid with two views; this page covers the view and column model in detail.

#Configuring views

Views are configured under state.view:

const defaultState: AdaptableUserState = {
  globalEntities: {
    availableColumns, // the columns views can use — see below
  },
  view: {
    currentViewId: 'all',
    views: [
      { id: 'all', label: 'All developers' },
      {
        id: 'by-language',
        label: 'By language',
        groupColumns: { 'language-group': { groupBy: 'preferredLanguage' } },
      },
    ],
  },
};
  • views — the list of views. You need at least one, and there is no upper limit.
  • Each view needs a unique id and a label (shown in the view picker and the settings panel).
  • currentViewId — the id of the active view. Exactly one view is active at a time.
  • viewDefaults — optional fallbacks for all views: dateFormat, singleColumnSort, selectionMode, keyboardNavigation, contextMenu and dataSource. A view's own setting wins. See Selection for how selectionMode resolves, and Keyboard navigation for keyboardNavigation.

#Table and pivot views

There are two kinds of views:

  • Table views show rows and columns, optionally grouped and aggregated — see Table views.
  • Pivot views spread the distinct values of one or more columns across the header and aggregate the data under them — see Pivot views.

The kind follows from the shape: a view with a pivotColumns array (even an empty one) is a pivot view; any other view is a table view. The two kinds have different column models, so there is no conversion between them — the UI and the API create one or the other.

#Available columns

Views don't define columns; they pick from the columns declared in state.globalEntities.availableColumns — an object keyed by column id, whose values are column definitions. The keys are listed in no particular order: order and visibility belong to each view.

import type { AdaptableColumnConfig } from '@adaptabletools/datagrid-vue';

const availableColumns: Record<string, AdaptableColumnConfig> = {
  // bound to a data field
  firstName: { field: 'firstName', dataType: 'text' },
  salary: { field: 'salary', dataType: 'number', aggregatable: true },
  // computed by a function
  fullName: {
    valueGetter: ({ data }) => `${data.firstName} ${data.lastName}`,
    dataType: 'text',
  },
  // computed by an AdaptableQL expression
  monthlySalary: { expression: '[salary] / 12', dataType: 'number' },
};

A column has a dataType and exactly one of:

  • field — the property of the data object the column is bound to;
  • valueGetter — ({ data }) => value, for values you compute in code;
  • expression — an AdaptableQL expression. These are calculated columns; in the expression, [colId] refers to a column id, not a data field.

A view can also declare columns only it can use, in its own privateEntities.availableColumns — see Table views.

#Column properties

These properties are core to what a column is, and can only be set in the column definition:

  • columnType — string | string[] | null, see Column types.
  • dataType (required) — 'text' | 'number' | 'boolean' | 'date' | 'array'.
  • field, valueGetter or expression — where the value comes from.
  • filterable, filterOperators — column filter settings (see Column filters).
  • renderValue, renderGroupValue, renderHeader — custom renderers. They receive the Infinite Table render params plus adaptableColumn and view.

The following properties can be set in the column definition and overridden per view (see Columns in a view):

  • aggregation — the aggregation shown on group rows, see Aggregations.
  • checkboxSelection — render a selection checkbox in this column (with 'multi-row' selection, see Selection checkboxes).
  • components — custom Infinite Table column components.
  • editable, exportable, resizable.
  • filterType, filterValues — the column filter type and its values.
  • label — the header text. When omitted, the field (or the column id) is humanized: lastName becomes Last name.
  • pinned — pin the column to the start.
  • rowGroupable, pivotable, aggregatable — whether users can group, pivot and aggregate by the column. All default to true.
  • sortable, sortType — see Sorting.
  • visible — defaults to true.
  • width, flex, minWidth, maxWidth — sizing. When flex is set, it wins over width.

When a view needs a column with a different renderer or data source, define it as a separate column.

#Columns in a view

A table view lays out the available columns with four optional properties:

  • columnOrder — the ordered list of column ids in the view. It doubles as the inclusion list: columns not listed are not in the view. When omitted, the view shows every available column, in definition order. Ids that don't match an available column are ignored.
  • columnOverrides — sparse, per-column overrides of the properties listed above, keyed by column id: { salary: { label: 'Pay', width: 160 } }.
  • columnVisibility — hidden columns, as { columnId: false }. A hidden column keeps its position in columnOrder, so showing it again puts it back in place. It has the final say over visible in column definitions and overrides.
  • includeColumns / excludeColumns — restrict which available columns the view can use at all, including in its column pickers.
#
Column order, overrides and visibility

The Compact view reorders columns, relabels and pins lastName, relabels salary, and hides country. The Without salary view has no columnOrder, so it shows every available column except the excluded salary.

open
loading demo…

As users resize, reorder, pin or hide columns, the grid writes the result back into these same properties of the current view.

Pivot views don't use this model: they are built from pivotColumns, pivotAggregationColumns and pivotGroupColumns — see Pivot views.

#Group columns

Row grouping adds synthetic group columns to a table view, declared in its groupColumns record, keyed by id:

{
  id: 'by-language',
  label: 'By language',
  columnOrder: ['language-group', 'firstName', 'salary'],
  groupColumns: {
    'language-group': { groupBy: 'preferredLanguage', label: 'Language' },
  },
},

The id of a group column doesn't reference an available column — any id works, as long as it's unique in the view. groupBy names the column(s) to group by. Group columns take the same overridable properties as regular columns, and you place them with columnOrder like any other column; group columns missing from columnOrder render first. Table views covers grouping in detail.

#Column defaults

Instead of repeating properties on every column, set them once in globalEntities:

  • columnDefaults — applied to every column.
  • dataTypeDefaults — applied to every column of a data type, keyed by dataType: { number: { minWidth: 160 } }.
  • columnTypeDefaults — applied to every column with a given columnType.

Defaults accept the overridable column properties listed above, plus filterable and filterOperators. The more specific setting wins:

  1. the built-in defaults;
  2. columnDefaults;
  3. dataTypeDefaults[dataType];
  4. columnTypeDefaults[columnType] — for several column types, in array order, the last one winning;
  5. the column definition in availableColumns;
  6. the view's columnOverrides.

A view's privateEntities can carry its own columnDefaults, dataTypeDefaults and columnTypeDefaults; they are merged over the global ones for that view only.

#Column types

columnType tags a column with one or more types — a string, an array of strings, or null for none. A column type is just a name, with two uses:

  • Shared properties — give every column of a type the same settings through columnTypeDefaults. A type without an entry there adds no properties.
  • Scoping — target columns by type in other features. For example, tag the money columns with columnType: 'currency', then format them all with one styled cell scoped to columnTypes: ['currency'] — columns added later with the same tag are covered automatically.
#
Column defaults, data type defaults and column types

Every column gets flex: 1 and minWidth: 120 from columnDefaults; number columns get a larger minWidth from dataTypeDefaults. The two name columns are tagged columnType: 'name', which pins them, gives them a fixed width and makes them non-resizable. The salary definition sets its own flex: 2, which wins over every default.

open
loading demo…

#Date columns

Columns with dataType: 'date' accept Date objects or date strings that Date.parse understands (such as ISO yyyy-mm-dd); both sort chronologically. Date objects render in the user's locale format, strings render as they are. To format dates your way, use a styled cell with a date format.

#
Date columns

firstRelease holds Date objects, latestRelease holds ISO strings. Both are date columns and sort as dates — the view is sorted by latestRelease, newest first.

open
loading demo…

#Managing views in the UI

<Adaptable.UI /> shows a view picker when the dashboard has a view widget:

dashboard: {
  top: { widgets: [{ id: 'views', type: 'view' }] },
},

The settings panel has a Views page to create (table or pivot), rename, clone, delete and switch views, and pages that edit the current view: Columns, Sorting, Grouping, Aggregations, Filter and Selection & navigation for table views; Pivot columns, Sorting, Row groups, Aggregations and Selection & navigation for pivot views. The Columns page has a column inspector that edits every property of a column for the current view — see Editing columns in the UI.

Each of these is also available standalone, inside an Adaptable.Provider: Adaptable.UI.ViewPicker, Adaptable.UI.ViewManager, Adaptable.UI.ViewColumnsEditor, Adaptable.UI.ViewSortingEditor, Adaptable.UI.ViewGroupingEditor, Adaptable.UI.ViewAggregationsEditor, Adaptable.UI.ViewGridFilterEditor, Adaptable.UI.ViewSelectionEditor and Adaptable.UI.ViewPivotColumnsEditor — plus the compact Adaptable.UI.ColumnChooser, Adaptable.UI.GroupingEditor and Adaptable.UI.PivotEditor. To swap an editor inside the settings panel for your own, pass it through the Provider's components prop (for example components.ViewGroupingEditor).

For fully custom UIs, the view composables expose the same operations on the current view. Each returns one ComputedRef of an object: read it through .value in the script, and directly in the template.

  • useViews — list, switch, create, clone, rename and delete views;
  • useViewColumns, useColumnSizing, useColumnPinning, useColumnLabels, useColumnProperties — the table column model and the properties of each column in the view;
  • useColumnSorting, useColumnGrouping, useColumnAggregations;
  • usePivotColumns, usePivotGrouping — pivot views;
  • useViewSelection — the selection mode, the selection checkbox column and keyboard navigation.
import { useViews } from '@adaptabletools/datagrid-vue';

// in the setup of a component inside Adaptable.Provider
const viewsModel = useViews();

// a ComputedRef: read its value where you use it, so it is always current
function onSomeEvent() {
  const {
    views, // all views in state
    currentViewId,
    setActiveView, // (viewId) => void
    createTableView, // (view?) => id
    createPivotView, // (view?) => id
    cloneView, // (viewId) => id of the clone
    renameView, // (viewId, label) => void
    deleteView, // (viewId) => void — not for the last view (see canDeleteView)
  } = viewsModel.value;

  // ...
}
#
A custom view switcher

The buttons above the grid come from useViews: one per view (including a pivot view) plus a button that clones the current view and switches to the clone.

open
loading demo…