Adaptable

#Getting Started

Install the package:

npm install @adaptabletools/datagrid-vue@canary
Note

Version 0.9 is published on the canary dist-tag until its stable release: @canary installs the latest canary.

The package needs Vue 3.4 or newer.

Import the stylesheet once, at the root of your app:

import '@adaptabletools/datagrid-vue/index.css';

#Your first grid

In order to render your first grid, you need 3 important things:

  • a data prop (an array, a promise, or a fetch function)
  • a defaultState object that includes the available columns and an active view.
  • a primaryKey for your data
<script setup lang="ts">
import {
  Adaptable,
  type AdaptableUserState,
  type AdaptableColumnConfig,
} from '@adaptabletools/datagrid-vue';

1. grab your data - array, promise or fetch function
import { data } from './basic.data';

2a. define the available columns
const availableColumns: Record<string, AdaptableColumnConfig> = {
  firstName: { field: 'firstName', dataType: 'text' },
  country: { field: 'country', dataType: 'text' },
  salary: {
    field: 'salary',
    dataType: 'number',
    aggregatable: true,
    renderValue: ({ value }) =>
      value == null ? null : `$${(value as number).toLocaleString('en-US')}`,
  },
};

const defaultState: AdaptableUserState = {
  globalEntities: {
    columnDefaults: { width: 140 },
    // an object where the keys are the column ids
    // and the values are the column configurations
    // { firstName: { field: 'firstName', dataType: 'text' }, ... }
    availableColumns,
  },
  dashboard: {
    top: { widgets: [{ id: 'views', type: 'view' }] },
  },
  view: {
    2b. define your views
    currentViewId: 'flat',

    views: [
      {
        // all columns are shown by default
        id: 'flat',
        label: 'All developers',
      },
      {
        id: 'second view',
        label: 'Specific column order',
        columnOrder: ['firstName', 'preferredLanguage', 'salary', 'country'],
      },
    ],
  },
};
</script>

<template>
  3. configure your primary key
  <Adaptable.Provider primaryKey="id"
    adaptableId="docs-basic"
    :data="data"
    :defaultState="defaultState"
  >
    <Adaptable.UI />
  </Adaptable.Provider>
</template>
Note

You need to configure the primaryKey of your data, so Adaptable will know to properly handle and reference your row data.

In a Vue template

Adaptable is one import. In <script setup> its components are used in the template as they are: <Adaptable.Provider>, <Adaptable.UI />, <Adaptable.Workspace />.

Props have the same names as in React, bound the Vue way: :data, :defaultState, :onStateChange.

#
Your first Adaptable DataGrid

Two views over the same data — switch them from the picker in the dashboard.

Interact with a view, switch to another, then switch back — you’ll find it as you left it.

open
loading demo…

Three things to notice:

  • availableColumns declares every column the grid knows about — label, data type, width, renderers and any other column properties. Views then pick and arrange them.
  • views are first-class: the columnOrder, sorting and grouping you see is just state. Users can change it at runtime, and you can persist the result.
  • <Adaptable.Workspace /> renders the full product — the datagrid, the settings panel, dashboard, view picker. When you need custom UI layouts, compose Adaptable.Workspace, Adaptable.UI.DataGrid, Adaptable.UI.Dashboard and friends yourself — see UI.
Note

State passed via defaultState is uncontrolled — the grid owns it after mount. Pass state + onStateChange instead when you want to own it.

#Next steps

  • Loading data — client vs server mode, TDGP, TanStack Query
  • Theming — tokens, dark mode, accent presets