Skip to content

Data Grid accessories

Optional parts of the Data Grid, passed in its accessories option. They attach when the grid is created (the grid must be in the document), and a grid that uses none ships none of them.

Accessory What it adds
columnMenu(options?) The header menu: sorting, filter, pinning, grouping, hiding, Groups and Columns submenus. items(column, defaults) changes the entries.
contextMenu(options?) The cell menu: copy (with or without headers), cut, paste, notes, pin row, Move row, Send to, Groups, Columns, Export. items(target, defaults) changes the entries; export: { excel, pdf } adds those formats.
columnChooser() A dialog that shows, hides, and reorders columns at once (open()).
sideBar(options?) Columns and Filters panels beside the rows (panels, position, open, width).
statusBar(options?) Row counts, the selected count, aggregates of the cell ranges, and panels of your own.
toolbar(options) Built-in buttons and buttons or menus of your own, next to the search box and the group and pivot panels.
tooltips(options?) Delay, truncated-only, and hover-only modes for column tooltips.
find(options?) A search field over the displayed cells; F3 and Shift+F3 move between matches.
notes(options) Cell notes stored by your application (store: { get, set, index }, author); Shift+F2 opens the note dialog.
import { DataGrid } from '@absoluteui/components/data-grid';
import { columnMenu, contextMenu, find, statusBar } from '@absoluteui/components/data-grid/accessories';
interface Person {
id: string;
name: string;
age: number;
}
const host = document.createElement('div');
host.style.setProperty('block-size', '300px');
document.body.append(host);
DataGrid.create<Person>(host, {
label: 'People',
rows: [{ id: '1', name: 'Ada', age: 36 }, { id: '2', name: 'Ben', age: 29 }],
rowId: (r) => r.id,
cellSelection: true,
accessories: [columnMenu(), contextMenu(), find(), statusBar()],
columns: [
{ id: 'name', header: 'Name', field: 'name', filter: 'text' },
{ id: 'age', header: 'Age', field: 'age', type: 'number' },
],
});
  • Entries that do not apply are left out of the menus; actions taken from a menu behave like their keyboard and pointer counterparts. Shift+F10 or the ContextMenu key opens the menu of the focused header or cell; outside headers and cells the browser’s menu stays.
  • Your own menu entries are { id, label, action, disabled, shortcut, icon, items }; toolbar buttons are { id, label, icon, action } or items for a menu. Labels are text, never HTML.
  • Find matches cells of the displayed rows (all pages; rows of collapsed groups are not searched); findShortcut: true opts into Ctrl+F.
  • The grid stores no notes: the store you pass decides where they live. An empty note deletes.
  • Status bar and custom panels refresh after every change; aggregates appear while the cell ranges cover two cells or more.

columnChooser

The column chooser: a dialog with the column list (search, Show all, per column a checkbox and Move up / Move down). Opened by the column menu’s Columns > Choose columns entry, or by open().

function columnChooser<Row>(): DataGridColumnChooser<Row>;

columnMenu

The column menu: a header button, a right-click on a header, or Shift+F10 / the ContextMenu key on a header.

function columnMenu<Row>(options?: DataGridColumnMenuOptions): DataGridAccessory<Row>;

contextMenu

The cell menu: a right-click on a cell, or Shift+F10 / the ContextMenu key on a focused cell.

function contextMenu<Row>(options?: DataGridContextMenuOptions<Row>): DataGridAccessory<Row>;

find

Find in the grid: a search field in the toolbar with Previous and Next buttons. Matching cells of the displayed rows (formatted text) are marked, the current one more strongly; it is scrolled into view (and its page shown) and announced (“Match 2 of 15”). Enter and Shift+Enter in the field, and F3 and Shift+F3 in the grid, move between matches. Focus stays where it is.

function find<Row>(options?: DataGridFindOptions): DataGridFind<Row>;

notes

Cell notes: a marked cell has a note (and says “has a note” to assistive technology). Shift+F2 on a cell, the cell menu’s Add note / Edit note, or a click on the mark opens a dialog to read, write, or delete the note (read-only notes only show). Changes go to the store.

function notes<Row>(options: DataGridNotesOptions): DataGridAccessory<Row>;

sideBar

function sideBar<Row>(options?: DataGridSideBarOptions): DataGridAccessory<Row>;

statusBar

The status bar: a named group below the grid with row counts (“Rows: 120 of 500”), the selected row count, and the sum, average, minimum, maximum, and count of the numbers in the cell ranges (shown while the ranges cover two cells or more). Not a live region: counts are announced by the grid where they change.

function statusBar<Row>(options?: DataGridStatusBarOptions<Row>): DataGridAccessory<Row>;

toolbar

Toolbar buttons above the grid (next to the search box and the group and pivot panels): a role="toolbar" with one tab stop; arrow keys, Home, and End move between its buttons. A button with items opens a menu.

function toolbar<Row>(options: DataGridToolbarOptions): DataGridAccessory<Row>;

tooltips

Cell tooltips (a column’s tooltip): one shared tooltip (the Tooltip styles) that meets WCAG 1.4.13: it shows after a delay on hover and at once on keyboard focus, stays while the cell or the tooltip is hovered, and Escape dismisses it without moving focus. The cell references it with aria-describedby while it shows. Never on touch.

function tooltips<Row>(options?: DataGridTooltipsOptions): DataGridAccessory<Row>;

DataGridCellMenuTarget

interface DataGridCellMenuTarget<Row> {
readonly rowId: string;
readonly column: string;
readonly row: Row | undefined;
}

DataGridColumnChooser

interface DataGridColumnChooser<Row> extends DataGridAccessory<Row> {
open(): void;
}

DataGridColumnMenuOptions

interface DataGridColumnMenuOptions {
readonly items?: (column: string, defaults: readonly DataGridMenuEntry[]) => readonly DataGridMenuEntry[];
readonly button?: boolean;
}

DataGridContextMenuOptions

interface DataGridContextMenuOptions<Row> {
readonly items?: (target: DataGridCellMenuTarget<Row>, defaults: readonly DataGridMenuEntry[]) => readonly DataGridMenuEntry[];
readonly export?: DataGridMenuExport<Row> | false;
}

DataGridFind

interface DataGridFind<Row> extends DataGridAccessory<Row> {
find(text: string): number;
next(): void;
previous(): void;
}

DataGridFindOptions

interface DataGridFindOptions {
readonly caseSensitive?: boolean;
readonly shortcut?: boolean;
}

DataGridMenuAction

A menu entry of your own.

interface DataGridMenuAction {
readonly id: string;
readonly label: string;
readonly action?: () => void;
readonly disabled?: boolean;
readonly shortcut?: string;
readonly icon?: string;
readonly items?: readonly DataGridMenuEntry[];
}

DataGridMenuExport

The cell menu’s Export submenu: CSV always, Excel when excel is given (for example toXlsx from data-grid/export).

interface DataGridMenuExport<Row> {
readonly filename?: string;
readonly csv?: DataGridCsvOptions<Row>;
readonly excel?: (grid: DataGrid<Row>) => Promise<Blob>;
readonly pdf?: (grid: DataGrid<Row>) => Promise<Blob>;
}

DataGridNote

A cell note (stored by your application).

interface DataGridNote {
readonly text: string;
readonly author?: string;
readonly updated?: string;
readonly readOnly?: boolean;
}

DataGridNotesOptions

interface DataGridNotesOptions {
readonly store: DataGridNoteStore;
readonly author?: string;
}

DataGridNoteStore

Where notes live: your application reads and writes them; the grid stores nothing.

interface DataGridNoteStore {
get(rowId: string, column: string): Promise<DataGridNote | null>;
set(rowId: string, column: string, note: DataGridNote | null): Promise<void>;
index?(): Promise<readonly {
readonly rowId: string;
readonly column: string;
}[]>;
}

DataGridSideBarOptions

interface DataGridSideBarOptions {
readonly panels?: readonly DataGridSidePanelName[];
readonly position?: 'start' | 'end';
readonly open?: DataGridSidePanelName | null;
readonly width?: number;
}

DataGridStatusBarOptions

interface DataGridStatusBarOptions<Row> {
readonly panels?: readonly (DataGridStatusPanelName | DataGridStatusPanel<Row>)[];
readonly format?: (value: number, aggregate: 'sum' | 'avg' | 'min' | 'max' | 'count') => string;
}

DataGridStatusPanel

A status bar panel of your own: its text (or node), refreshed after every change.

interface DataGridStatusPanel<Row> {
readonly id: string;
readonly render: (context: DataGridAccessoryContext<Row>) => string | Node;
}

DataGridToolbarOptions

interface DataGridToolbarOptions {
readonly items: readonly DataGridToolbarItem[];
readonly label?: string;
}

DataGridTooltipsOptions

interface DataGridTooltipsOptions {
readonly showDelay?: number;
readonly mode?: 'always' | 'truncated';
readonly trigger?: 'hover' | 'hover-focus';
}

DataGridCellMenuItem

Built-in cell menu entries.

type DataGridCellMenuItem = 'copy' | 'copyWithHeaders' | 'cut' | 'paste' | 'note' | 'pinRow' | 'moveRow' | 'moveUp' | 'moveDown' | 'sendTo' | 'export' | 'exportCsv' | 'exportExcel' | 'exportPdf' | 'autoSizeAll' | 'groups' | 'expandAll' | 'collapseAll' | 'resetColumns' | 'columns';

DataGridColumnMenuItem

Built-in column menu entries.

type DataGridColumnMenuItem = 'sortAscending' | 'sortDescending' | 'clearSort' | 'filter' | 'pin' | 'autoSize' | 'autoSizeAll' | 'group' | 'groups' | 'expandAll' | 'collapseAll' | 'hide' | 'rename' | 'chooser' | 'resetColumns' | 'columns';

DataGridMenuEntry

type DataGridMenuEntry = DataGridColumnMenuItem | DataGridCellMenuItem | 'separator' | DataGridMenuAction;

DataGridSidePanelName

type DataGridSidePanelName = 'columns' | 'filters';

DataGridStatusPanelName

type DataGridStatusPanelName = 'rows' | 'selected' | 'aggregates';

DataGridToolbarItem

A toolbar entry: a built-in, a button of your own, or a menu button.

type DataGridToolbarItem = 'chooser' | 'resetColumns' | 'autoSizeAll' | 'expandAll' | 'collapseAll' | 'separator' | {
readonly id: string;
readonly label: string;
readonly icon?: string;
readonly action?: () => void;
readonly items?: readonly DataGridMenuEntry[];
};