Skip to content

DataGrid

DataGrid

An interactive data table (role="grid") following the APG Grid pattern: one tab stop, arrow-key navigation between cells (Home/End, Ctrl+Home/Ctrl+End, PageUp/PageDown; Up/Down keep the visual column, so a grouped header with spanning cells works), Enter/F2 to interact with a cell's widgets and Escape to return to the cell. A composite widget in a cell (a Toolbar, RadioGroup, TabList, …) is entered with Enter/F2 like a text field; it manages its own tab indexes, so it keeps its own Tab stop. Supports sortable columns (onSortChange reports the new sort; a grid with items orders its rows by the sorted column's compare, otherwise the consumer orders them) and single or multiple row selection with a select-all header checkbox.

Selection is made with the row's control, Space on a cell, and, with selectOnRowClick, a click on the row. selectionAppearance picks the fill of a selected row, subtleSelection hides the unchecked controls until their row (or, for select-all, the grid) is hovered or holds focus, and a row's selectionCellProps disables, hides or names its control. The selection column comes first; a DataGrid.SelectionCell places it elsewhere in a row.

The grid is composed from its parts, or rendered from data: with items and typed columns (DataGridColumn<T>, see createTableColumn) it renders the header, the rows and the cells itself, and DataGrid.Body also takes a render function that returns each item's row. Rows rendered from items take their rowId from getRowId (by default the item's index).

With items, selection follows the data rather than the rendered rows: select-all and its checkbox cover every item (isSelectionDisabled leaves items out), and ids of rows that are filtered out, on another page or not rendered stay selected through row clicks, select-all and sorting, and are reported by onSelectedItemsChange.

With items and columns, the columns can be sized: resizableColumns gives each column header a resize handle (a separator that a pointer drags and the arrow keys move, mirrored in right-to-left grids; F2 on a column header moves focus to it, and Enter, Space or Escape back), columnSizingOptions sets each column's initial and minimum width, and columnWidths or defaultColumnWidths with onColumnWidthsChange(widths, details) hold the widths, for instance to persist them (Fluent's resizableColumns, columnSizingOptions and onColumnResize, whose data is in details). The grid then lays its columns out from the widths and truncates its cells' text.

With items and columns, a virtualWindow (from useVirtualWindow) renders only the rows in view of a long list, with spacer rows for the others: the scroll wrapper (containerProps) needs a bounded height, and every row has the window's fixed row height. The header stays at the top of the wrapper, the keyboard moves by the data (a row that is not rendered is scrolled in before it gets focus), the focused row stays rendered, and selection, select-all, sorting and column sizing still cover every item. The grid then carries aria-rowcount and its rows aria-rowindex, so assistive technology reads each row's place in the whole list. Fluent's DataGrid has no built-in counterpart.

size sets the density (medium, small or extra-small), and focusMode how focus moves: by cell (the default), by row or not at all (Fluent's focusMode); a cell opts out of the arrow-key navigation, or becomes its own focus target, with its own focusMode. The rows of a <tfoot> child of a windowed grid are numbered after the data rows (aria-rowindex, aria-rowcount) and navigated like the others.

Cells, headers and footer rows of your own read and change the grid through three hooks: useDataGridSort (the sort, and setSort, which calls onSortChange as a sortable header does), useDataGridSelection (the selected ids, isSelected, and toggle, which calls onSelectedItemsChange as a row's selection control does) and useDataGridRowId (the id of the row around a cell).

Sub-components are available as DataGrid.Header, DataGrid.HeaderCell, DataGrid.Body, DataGrid.Row, DataGrid.Cell and DataGrid.SelectionCell in client components, and as the flat exports DataGridHeader, DataGridHeaderCell, DataGridBody, DataGridRow, DataGridCell and DataGridSelectionCell (the form React Server Components can import).

Examples

Default

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const Default: Story = {};

From Columns

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const FromColumns: Story = {
  render: (args) => <ColumnsGrid {...args} />,
};

Multiple Selection

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const MultipleSelection: Story = {
  args: {
    selectionMode: 'multiple',
    defaultSelectedItems: ['2'],
  },
};

Single Selection

SelectionStatus
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const SingleSelection: Story = {
  args: {
    selectionMode: 'single',
    defaultSelectedItems: ['1'],
  },
  render: (args) => <ColumnsGrid {...args} />,
};

Interactive Cells

NameNotesActions
Alice Johnson
Bob Smith
Carol White
export const InteractiveCells: Story = {
  args: {
    'aria-label': 'Team notes',
  },
  render: ({ onSortChange: _onSortChange, ...args }) => (
    <DataGrid {...args}>
      <DataGrid.Header>
        <tr>
          <DataGrid.HeaderCell>Name</DataGrid.HeaderCell>
          <DataGrid.HeaderCell>Notes</DataGrid.HeaderCell>
          <DataGrid.HeaderCell>Actions</DataGrid.HeaderCell>
        </tr>
      </DataGrid.Header>
      <DataGrid.Body>
        {MEMBERS.slice(0, 3).map((member) => (
          <DataGrid.Row key={member.id} rowId={member.id}>
            <DataGrid.Cell>{member.name}</DataGrid.Cell>
            <DataGrid.Cell>
              <input
                aria-label={`Notes for ${member.name}`}
                defaultValue=""
                className="h-8 w-full rounded border border-wave-input bg-wave-background px-2 text-wave-body-1 text-wave-foreground focus:border-b-2 focus:border-b-wave-primary focus:outline-hidden"
              />
            </DataGrid.Cell>
            <DataGrid.Cell>
              <button
                type="button"
                className="rounded border border-wave-stroke bg-wave-background px-3 py-1 text-wave-body-1 text-wave-foreground hover:bg-wave-subtle-hover focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-wave-ring"
              >
                Edit {member.name}
              </button>
            </DataGrid.Cell>
          </DataGrid.Row>
        ))}
      </DataGrid.Body>
    </DataGrid>
  ),
};

Horizontal Scroll

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const HorizontalScroll: Story = {
  args: {
    containerProps: { className: 'max-w-md' },
    className: 'min-w-[48rem]',
  },
};

Typed Columns And Sorting

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const TypedColumnsAndSorting: Story = {
  render: (args) => (
    <MemberGrid {...args} defaultSort={{ columnId: 'name', direction: 'ascending' }} />
  ),
};

Select On Row Click

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const SelectOnRowClick: Story = {
  args: {
    selectionMode: 'multiple',
    selectOnRowClick: true,
    defaultSelectedItems: ['2'],
  },
  render: (args) => <MemberGrid {...args} />,
};

Menu In Cell

StatusActions
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const MenuInCell: Story = {
  args: {
    'aria-label': 'Team members with actions',
    selectionMode: 'multiple',
    selectOnRowClick: true,
  },
  render: (args) => <MemberGrid {...args} columns={MEMBER_COLUMNS_WITH_ACTIONS} />,
};

Selection Appearances

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const SelectionAppearances: Story = {
  args: {
    selectionMode: 'multiple',
    defaultSelectedItems: ['1', '3'],
  },
  render: (args) => (
    <div className="flex flex-col gap-6">
      {(['brand', 'neutral', 'none'] as const).map((appearance) => (
        <MemberGrid
          key={appearance}
          {...args}
          aria-label={`Team members, ${appearance} selection`}
          selectionAppearance={appearance}
        />
      ))}
    </div>
  ),
};

Subtle Selection

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const SubtleSelection: Story = {
  args: {
    selectionMode: 'multiple',
    subtleSelection: true,
    selectOnRowClick: true,
    defaultSelectedItems: ['4'],
  },
  render: (args) => <MemberGrid {...args} />,
};

Selection Cell At The End

NameRole
Alice JohnsonEngineer
Bob SmithDesigner
Carol WhiteManager
David BrownAnalyst
export const SelectionCellAtTheEnd: Story = {
  args: {
    'aria-label': 'Team members, selection at the end',
    selectionMode: 'multiple',
    defaultSelectedItems: ['1'],
  },
  render: ({ onSortChange: _onSortChange, ...args }) => (
    <DataGrid {...args}>
      <DataGrid.Header>
        <tr>
          <DataGrid.HeaderCell>Name</DataGrid.HeaderCell>
          <DataGrid.HeaderCell>Role</DataGrid.HeaderCell>
          <DataGrid.SelectionCell />
        </tr>
      </DataGrid.Header>
      <DataGrid.Body>
        {MEMBERS.map((member) => (
          <DataGrid.Row key={member.id} rowId={member.id}>
            <DataGrid.Cell>{member.name}</DataGrid.Cell>
            <DataGrid.Cell>{member.role}</DataGrid.Cell>
            <DataGrid.SelectionCell disabled={member.status === 'On leave'} />
          </DataGrid.Row>
        ))}
      </DataGrid.Body>
    </DataGrid>
  ),
};

Custom Cell

Selected
Alice JohnsonEngineerSeattle
Bob SmithDesignerNew York
Carol WhiteManagerLondon
David BrownAnalystOslo
1 selectedSorted by name, ascending
export const CustomCell: Story = {
  args: {
    'aria-label': 'Team members with custom cells',
    selectionMode: 'multiple',
    defaultSelectedItems: ['2'],
  },
  render: (args) => <CustomCellGrid {...args} />,
};

Paging

Status
Member 1EngineerSeattleActive
Member 2DesignerNew YorkActive
Member 3ManagerLondonActive
Member 4AnalystOsloActive
Member 5EngineerTokyoOn leave
Member 6DesignerSeattleActive
Member 7ManagerNew YorkActive
Member 8AnalystLondonActive
Member 9EngineerOsloActive
Member 10DesignerTokyoActive
Member 11ManagerSeattleActive
Member 12AnalystNew YorkActive
Member 13EngineerLondonActive
Member 14DesignerOsloOn leave
Member 15ManagerTokyoActive
Member 16AnalystSeattleActive
Member 17EngineerNew YorkActive
Member 18DesignerLondonActive
Member 19ManagerOsloActive
Member 20AnalystTokyoActive
Page 1 of 100 selected
export const Paging: Story = {
  args: {
    'aria-label': 'Team members, paged',
    selectionMode: 'multiple',
  },
  render: (args) => <PagedGrid {...args} />,
};

Resizable

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const Resizable: Story = {
  args: {
    'aria-label': 'Team members, resizable columns',
    resizableColumns: true,
    columnSizingOptions: MEMBER_COLUMN_SIZING,
    onColumnWidthsChange: fn(),
  },
  render: (args) => <MemberGrid {...args} />,
};

Resizable Controlled

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive

Widths: name 220, role 160, location 160, status 140

export const ResizableControlled: Story = {
  args: {
    'aria-label': 'Team members, controlled column widths',
    resizableColumns: true,
    onColumnWidthsChange: fn(),
  },
  render: (args) => <ControlledWidthsGrid {...args} />,
};

Ten Thousand Rows

Status
Member 00001EngineerSeattleActive
Member 00002AnalystLondonActive
Member 00003ManagerTokyoActive
Member 00004DesignerNew YorkActive
Member 00005EngineerOsloOn leave
Member 00006AnalystSeattleActive
Member 00007ManagerLondonActive
Member 00008DesignerTokyoActive
Member 00009EngineerNew YorkActive
Member 00010AnalystOsloActive
Member 00011ManagerSeattleActive
Member 00012DesignerLondonActive
Member 00013EngineerTokyoActive
Member 00014AnalystNew YorkOn leave
Member 00015ManagerOsloActive
Member 00016DesignerSeattleActive
Member 00017EngineerLondonActive

Mounted rows: 0 of 10,000

export const TenThousandRows: StoryObj<TenThousandRowsArgs> = {
  args: {
    'aria-label': 'Ten thousand members',
    itemSize: 44,
    selectionMode: 'multiple',
    resizableColumns: true,
    onColumnWidthsChange: fn(),
  },
  argTypes: {
    // Heights a row's cells fit in; a smaller one would overlap the rows.
    itemSize: { control: 'select', options: [44, 52, 60] },
  },
  render: (args) => <TenThousandRowsGrid {...args} />,
};

Sizes

Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
Status
Alice JohnsonEngineerSeattleActive
Bob SmithDesignerNew YorkActive
Carol WhiteManagerLondonOn leave
David BrownAnalystOsloActive
export const Sizes: Story = {
  render: (args) => (
    <div className="flex flex-col gap-6">
      {(['medium', 'small', 'extra-small'] as const).map((size) => (
        <HeaderChildrenGrid
          key={size}
          {...args}
          size={size}
          selectionMode="multiple"
          aria-label={`Team members, ${size}`}
        />
      ))}
    </div>
  ),
};

Focus Modes

RoleLocation
Alice JohnsonSeattle
Bob SmithNew York
Carol WhiteLondon
David BrownOslo
export const FocusModes: Story = {
  args: { focusMode: 'row', selectionMode: 'multiple' },
  argTypes: { focusMode: { control: 'inline-radio', options: ['cell', 'row', 'none'] } },
  render: (args) => <FocusGrid {...args} />,
};

Cell Focus Modes

RoleLocation
Alice JohnsonSeattle
Bob SmithNew York
Carol WhiteLondon
David BrownOslo
export const CellFocusModes: Story = {
  render: (args) => <FocusGrid {...args} cellFocusMode />,
};
Status
Member 00001EngineerSeattleActive
Member 00002AnalystLondonActive
Member 00003ManagerTokyoActive
Member 00004DesignerNew YorkActive
Member 00005EngineerOsloOn leave
Member 00006AnalystSeattleActive
Member 00007ManagerLondonActive
Member 00008DesignerTokyoActive
Member 00009EngineerNew YorkActive
Member 00010AnalystOsloActive
Member 00011ManagerSeattleActive
Member 00012DesignerLondonActive
Member 00013EngineerTokyoActive
Member 00014AnalystNew YorkOn leave
Member 00015ManagerOsloActive
Member 00016DesignerSeattleActive
Member 00017EngineerLondonActive
10,000 members
export const FooterRows: StoryObj<TenThousandRowsArgs> = {
  args: { 'aria-label': 'Ten thousand members with a footer', itemSize: 44 },
  render: ({ itemSize, ...args }) => {
    const Grid = () => {
      const virtualWindow = useVirtualWindow({ itemSize, scrollPaddingStart: itemSize });
      return (
        <DataGrid
          items={TEN_THOUSAND_MEMBERS}
          columns={TEN_THOUSAND_COLUMNS}
          getRowId={memberId}
          {...args}
          virtualWindow={virtualWindow}
          containerProps={{ className: 'h-120' }}
        >
          <tfoot>
            <tr>
              <td className="px-4 py-3 text-wave-body-1" colSpan={4}>
                10,000 members
              </td>
            </tr>
          </tfoot>
        </DataGrid>
      );
    };
    return <Grid />;
  },
};

Props

NameTypeRequiredDefaultDescription
size'medium' | 'small' | 'extra-small'No'medium'

The density of the grid: 'medium' (a one-line row is 44px tall), 'small' (34px) or 'extra-small' (24px, with the caption type size in the cells). It sets the padding of the cells, the header cells, the sort buttons and the selection cells, and the box of the media of a Table.CellLayout; a grid with a virtualWindow keeps its own row height. A class of your own on a part still wins. Rendered as data-size. Fluent's size.

focusMode'cell' | 'row' | 'none'No'cell'

How focus moves in the grid. 'cell': one Tab stop on a cell, and the arrow keys, Home/End, Ctrl+Home/Ctrl+End and PageUp/PageDown between cells; Enter or F2 enters a cell's widgets and Escape returns. 'row': one Tab stop on a body row (the header and a <tfoot> stay out), the arrow keys, Home/End and PageUp/PageDown between rows (on the row itself, never on a widget in it), the widgets of the other rows out of the Tab order and Tab inside the active row reaching its widgets; Space on a row still toggles its selection, and a row that holds focus is outlined. A grid with a virtualWindow navigates by cell whatever this says (a development warning). 'none': the grid handles no keys and writes no tabindex, so its widgets (sort buttons, selection controls) keep their own places in the Tab order and the cells are not focusable. Rendered as data-focus-mode. Fluent's focusMode ('row' is its 'row_unstable'; its 'composite', a two-level row and cell model of its focus library, has no counterpart).

getRowId(item: T) => stringNothe item's index in `items`, as a string

The row id of an item: the rowId of its row (for selection), for rows rendered from items. Select-all and its checkbox use these ids, whether the rows are rendered or not. A row's own rowId wins for that row, but a row whose own id differs from its item's id is outside select-all and its state, and select-all selects the item's id, which no row has (a development warning says so): return the rows' ids here rather than setting rowId. Ids must be unique (a duplicate warns in development). Define it outside the component, or memoise it: a new function rebuilds the row of every item and the set of ids select-all works on (with a virtualWindow, the component that holds the window renders at every row the view enters).

isSelectionDisabled(item: T, index: number) => booleanNo

Whether the selection of an item of items is disabled (index is its index in items), so select-all can skip items whose rows are not rendered. Select-all leaves such an item as it is, selected or not, and its state counts only the other items. The item's row takes it as the disabled of its selection cell (a disabled control; neither a row click nor Space changes it), unless the cell sets disabled itself: the cell's value then applies to the control, a value that disagrees warns in development, and select-all skips a row that either disables. Without it, every item is selectable unless its rendered row disables its selection cell. Ignored without items. Called for every item whenever items, getRowId or this function change: define it outside the component, or memoise it.

columnsreadonly DataGridColumn<T>[]No

Column definitions. When given and no DataGrid.Header child is present, the header row (including the selection column) is rendered from them: columnId becomes the header cell's columnId, renderHeaderCell() (else label) its content, and sortable (by default, having compare) makes it a sort button. With items and no DataGrid.Body child, the body rows are rendered from them too: one DataGrid.Cell per column, filled by renderCell. Those rows render again whenever the array changes, so keep it stable (defined outside the component, or memoised).

resizableColumnsbooleanNofalse

Gives the header cell of each column (of columns, by columnId; the last one included, the selection column not) a resize handle: a focusable role="separator" with the column's width as aria-valuenow. A drag (mouse, touch or pen) moves the column's end edge, mirrored in right-to-left grids. From the keyboard, F2 on a header cell (or on its sort button) moves focus to its handle, which adds no Tab stop to the grid; there the arrow keys move the edge by 20 pixels (5 with Shift, mirrored in right-to-left grids), Home sets the minimum width, and Enter, Space or Escape return focus to the header (its sort button, which Enter still activates directly). A double click sets the column back to its initial width once a width is state. The grid carries data-resizing while a handle drags. Needs columns and items, as every column width prop does: without them they are all ignored, with a development warning. Fluent's resizableColumns.

columnSizingOptionsRecord<string, ColumnSizingOption>No

The sizing of each column, by columnId: minWidth (@default 80), and the width it starts at, defaultWidth, else idealWidth, else 150 (never below minWidth). With it, or with columnWidths or defaultColumnWidths, the grid lays its columns out from these widths (a <colgroup> and a fixed table layout) with or without resizableColumns, and its cells truncate their text with an ellipsis unless a cell's class says otherwise. Until a width is state the grid is 100% wide and at least as wide as its columns, so a wider container spreads them (the selection column too); the first change takes the widths the columns are drawn at, so nothing jumps, and from then on the grid is exactly as wide as its columns (slack shows after the last one). There is no maximum width and no fitting to the container. Ids that are not columns are ignored; it may be written inline. Fluent's columnSizingOptions.

columnWidthsRecord<string, number>No

The column widths in pixels (controlled), by columnId; a column without an entry has its initial width (see columnSizingOptions), and a width below the column's minimum is held at it. The grid is exactly as wide as its columns. Pair it with onColumnWidthsChange; a parent that ignores a change leaves the column where it is.

defaultColumnWidthsRecord<string, number>No

The column widths in pixels at first render (uncontrolled; see columnWidths).

onColumnWidthsChange(widths: Record<string, number>, details: TableColumnWidthsChangeDetails) => voidNo

Called with the width of every column (by columnId) whenever a width changes, at every step of a drag (at most once per animation frame) or key press, then details: { columnId, width, event }, the resized column, its new width and the event behind it. The grid always passes details. Setting the width a column already has does not call it once a width is state. Fluent's onColumnResize, whose data is in details.

virtualWindowVirtualWindowNo

Renders only the body rows in view, plus an overscan, of a grid with many items: pass the result of useVirtualWindow({ itemSize }) (or an object of your own that implements VirtualWindow). The rows that are not rendered are replaced by spacer rows (aria-hidden, data-virtual-spacer) of their height. Fluent has no counterpart in its DataGrid.

The grid's scroll wrapper (the element of containerProps) becomes the window's scroller, so give it a bounded height, a height or a maximum height in containerProps: without one the window measures the whole list and renders every row (a development warning says so). Every row has the window's itemSize as its height (a window that measures its rows lays the grid out from its estimate: table rows are not measured): the grid sets it on each body row, drops the vertical padding of its cells and keeps their text on one line, so a cell's content must fit in it. The columns are laid out from widths (as with columnSizingOptions), so they never change width as rows come and go. The header stays at the top of the scroller: pass its height as scrollPaddingStart to useVirtualWindow, so keyboard moves bring rows into the area below it. The scroller is no tab stop of its own (tabIndex -1, as Firefox would stop on it; a tabIndex in containerProps wins), and the browser's scroll anchoring is off on it (the window lays the rows out).

The keyboard moves by the data: ArrowUp/ArrowDown, PageUp/PageDown and Ctrl+Home/Ctrl+End scroll a target row that is not rendered into the window, then focus it, and the focused row stays rendered when it is scrolled away. When a data change (a sort, new items) makes the browser drop focus from the moved row, focus returns to the same row, or to the row nearest its place. Sorting, selection, select-all and column sizing work on every item, rendered or not. The grid carries aria-rowcount (the items plus the header rows), every row aria-rowindex (1-based, the header rows first, the body rows in the sorted order) and every body row data-row-index (its 0-based position in the sorted order); a grid without a window renders none of them.

Needs items and columns, with the body rows rendered from them (no DataGrid.Body child, or one whose child is a render function); otherwise it is ignored, with a development warning. The component that calls useVirtualWindow renders again at every row the view enters: keep items, columns, getRowId and isSelectionDisabled stable (defined outside it, or memoised), or each of those renders rebuilds the rows of every item.

selectionMode'none' | 'single' | 'multiple'No'none'

Row selection mode. 'multiple' adds a checkbox column with a "Select all rows" header checkbox; 'single' adds a radio column (its header reads "Selection" to assistive technology). labels localizes both texts.

labelsDataGridLabelsNo

The grid's built-in text, for localization: the name of the select-all checkbox (selectAll), the header text of the selection column (selectionHeader), and, with resizableColumns, the name of the resize handles (resizeColumn) and their value text (columnWidth). Unset members keep their English defaults. Rows are named with their own selectionLabel.

selectOnRowClickbooleanNofalse

Whether a click on a body row toggles its selection in a selectable grid (single mode: selects the row alone, or clears it). The row's own onClick runs first; calling preventDefault() in it keeps the selection. A click never toggles when it lands on an interactive element in the row (a link, a button, an input, a label, an element with tabindex or a widget role, the selection control included), comes from a popup portaled from the row (a Menu, a Popover), or ends a text selection in the row (a drag across its text); nor does a click on a header row or on a row whose selection is disabled (selectionCellProps.disabled). Space on a cell toggles the row either way.

selectionAppearance'brand' | 'neutral' | 'none'No'brand'

How a selected row is filled: 'brand' with the selected token, 'neutral' with the subtle selected token, 'none' not at all (the selection control, aria-selected and, in forced colors, the row's outline still show it). Rendered as data-selection-appearance on the grid.

subtleSelectionbooleanNofalse

Subtle selection controls: a row's control is transparent while the row is not selected, until the row is hovered or holds focus, and the select-all checkbox while no row is selected, until the grid is hovered or holds focus. Forced colors and a coarse pointer (touch) always draw them; they stay focusable and named. Rendered as data-subtle-selection on the grid.

selectedItemsreadonly string[]No

Controlled selected row ids (DataGrid.Row rowId; with items, the ids from getRowId). With items, every id counts, whether its row is rendered, filtered out or on another page (see onSelectedItemsChange). In single mode pass at most one id: with several, only the first one is selected (without items, the first one whose row is rendered), and a development warning says so.

defaultSelectedItemsreadonly string[]No

Initially selected row ids (uncontrolled). In single mode, at most one (see selectedItems).

onSelectedItemsChange(selectedItems: string[], details: DataGridSelectedItemsChangeDetails) => voidNo

Called with the new selected row ids when the selection changes, then details ({ event }, the click or key press behind the change). A toggle of useDataGridSelection in a part of your own calls it as the row's control does.

With items, the selection follows the data: it reports every selected id, also ids whose rows are not rendered or not in items (filtered out, on another page, restored by id), and no change drops them. Select-all selects every item of items whose selection is not disabled (isSelectionDisabled, or the selection cell of its rendered row) and keeps every other id; when all of them are selected it removes only their ids. The select-all checkbox shows the state of those items. Both use the ids from getRowId (by default the item's index): a row that sets its own, different rowId (or a DataGrid.Row child whose rowId is no item's id) is outside them, and select-all then selects ids that no row has, with a development warning. Pass a getRowId that returns the rows' ids.

Without items (rows written as DataGrid.Row children), ids of rows that are not rendered are left out of the reported selection and of the select-all state, so the next change drops them. Until that change an uncontrolled grid still holds such an id: a row re-added with the same rowId before then is shown selected again.

containerPropsOmit<React.ComponentPropsWithRef<'div'>, 'children'>No

Props for the wrapper <div> around the <table>: a horizontally scrollable container (overflow-x-auto). Use it for its className, style (e.g. a max height) or ref. With a virtualWindow it is the window's scroller, which needs a bounded height. The wrapper is not a tab stop (the grid's own cell tab stop scrolls it) and has no role, so its aria-label/aria-labelledby are applied only together with a role (e.g. 'region'); without one they are dropped with a development warning. Name the grid with aria-label.

childrenReact.ReactNodeNo

DataGrid header, body, and row elements. Optional when items and columns render the grid; a generated body is placed after the header and before a <tfoot> child.

refReact.Ref<HTMLTableElement>No

Ref to the <table role="grid"> element.

itemsreadonly T[]No

The grid's data, one body row per item, in this order unless the sorted column has compare (see DataGridColumn.compare). With columns and no DataGrid.Body child (or one without children), the grid renders the rows and cells from the columns; a DataGrid.Body whose child is a render function renders the row of each item. Each row's rowId comes from getRowId. The grid reads the array and never changes it. onSortChange receives a DataGridSort object and details. items may not be undefined unless sort or defaultSort is given; pass items={data ?? []} while loading.

sortDataGridSort | nullNo

The controlled sort, or null for an unsorted grid.

defaultSortDataGridSort | nullNo

Initial sort while sort is not given yet.

onSortChange(sort: DataGridSort, details: DataGridSortChangeDetails) => voidNo

Called with the new sort when a sortable header is activated (or setSort of useDataGridSort is called), then details ({ event }). With items, the grid orders its rows by the sorted column's compare (see DataGridColumn.compare), also while sort is controlled; otherwise the consumer orders them.

Any other prop is passed to the element it renders (HTMLTableElement).

Parts

  • DataGrid.Header
  • DataGrid.HeaderCell
  • DataGrid.Body
  • DataGrid.Row
  • DataGrid.Cell
  • DataGrid.SelectionCell

Stable class names

PartClass
rootwave-data-grid
containerwave-data-grid__container
spacerwave-data-grid__spacer