Adaptable

#Getting Started

Install the package:

npm install @adaptabletools/datagrid-react@canary
Note

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

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

import '@adaptabletools/datagrid-react/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
import {
  Adaptable,
  AdaptableUserState,
  AdaptableColumnConfig,
} from '@adaptabletools/datagrid-react';

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

2a. define the available columns
export 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'],
      },
    ],
  },
};

export default function BasicDemo() {
  return (
    <Adaptable.Provider
      adaptableId="docs-basic"
      primaryKey="id"3. configure your primary key
      data={data}
      defaultState={defaultState}
    >
      <Adaptable.UI />
    </Adaptable.Provider>
  );
}
Note

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

#
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