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 Johnson | Engineer | Seattle | Active |
| Bob Smith | Designer | New York | Active |
| Carol White | Manager | London | On leave |
| David Brown | Analyst | Oslo | Active |
export const Default: Story = {};From Columns
| Status | |||
|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active |
| Bob Smith | Designer | New York | Active |
| Carol White | Manager | London | On leave |
| David Brown | Analyst | Oslo | Active |
export const FromColumns: Story = {
render: (args) => <ColumnsGrid {...args} />,
};Multiple Selection
| Status | ||||
|---|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active | |
| Bob Smith | Designer | New York | Active | |
| Carol White | Manager | London | On leave | |
| David Brown | Analyst | Oslo | Active |
export const MultipleSelection: Story = {
args: {
selectionMode: 'multiple',
defaultSelectedItems: ['2'],
},
};Single Selection
| Selection | Status | |||
|---|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active | |
| Bob Smith | Designer | New York | Active | |
| Carol White | Manager | London | On leave | |
| David Brown | Analyst | Oslo | Active |
export const SingleSelection: Story = {
args: {
selectionMode: 'single',
defaultSelectedItems: ['1'],
},
render: (args) => <ColumnsGrid {...args} />,
};Interactive Cells
| Name | Notes | Actions |
|---|---|---|
| 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 Johnson | Engineer | Seattle | Active |
| Bob Smith | Designer | New York | Active |
| Carol White | Manager | London | On leave |
| David Brown | Analyst | Oslo | Active |
export const HorizontalScroll: Story = {
args: {
containerProps: { className: 'max-w-md' },
className: 'min-w-[48rem]',
},
};Typed Columns And Sorting
| Status | |||
|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active |
| Bob Smith | Designer | New York | Active |
| Carol White | Manager | London | On leave |
| David Brown | Analyst | Oslo | Active |
export const TypedColumnsAndSorting: Story = {
render: (args) => (
<MemberGrid {...args} defaultSort={{ columnId: 'name', direction: 'ascending' }} />
),
};Select On Row Click
| Status | ||||
|---|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active | |
| Bob Smith | Designer | New York | Active | |
| Carol White | Manager | London | On leave | |
| David Brown | Analyst | Oslo | Active |
export const SelectOnRowClick: Story = {
args: {
selectionMode: 'multiple',
selectOnRowClick: true,
defaultSelectedItems: ['2'],
},
render: (args) => <MemberGrid {...args} />,
};Menu In Cell
| Status | Actions | ||||
|---|---|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active | ||
| Bob Smith | Designer | New York | Active | ||
| Carol White | Manager | London | On leave | ||
| David Brown | Analyst | Oslo | Active |
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 Johnson | Engineer | Seattle | Active | |
| Bob Smith | Designer | New York | Active | |
| Carol White | Manager | London | On leave | |
| David Brown | Analyst | Oslo | Active |
| Status | ||||
|---|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active | |
| Bob Smith | Designer | New York | Active | |
| Carol White | Manager | London | On leave | |
| David Brown | Analyst | Oslo | Active |
| Status | ||||
|---|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active | |
| Bob Smith | Designer | New York | Active | |
| Carol White | Manager | London | On leave | |
| David Brown | Analyst | Oslo | Active |
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 Johnson | Engineer | Seattle | Active | |
| Bob Smith | Designer | New York | Active | |
| Carol White | Manager | London | On leave | |
| David Brown | Analyst | Oslo | Active |
export const SubtleSelection: Story = {
args: {
selectionMode: 'multiple',
subtleSelection: true,
selectOnRowClick: true,
defaultSelectedItems: ['4'],
},
render: (args) => <MemberGrid {...args} />,
};Selection Cell At The End
| Name | Role | |
|---|---|---|
| Alice Johnson | Engineer | |
| Bob Smith | Designer | |
| Carol White | Manager | |
| David Brown | Analyst |
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 Johnson | Engineer | Seattle | ||
| Bob Smith | Designer | New York | ||
| Carol White | Manager | London | ||
| David Brown | Analyst | Oslo | ||
| 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 1 | Engineer | Seattle | Active | |
| Member 2 | Designer | New York | Active | |
| Member 3 | Manager | London | Active | |
| Member 4 | Analyst | Oslo | Active | |
| Member 5 | Engineer | Tokyo | On leave | |
| Member 6 | Designer | Seattle | Active | |
| Member 7 | Manager | New York | Active | |
| Member 8 | Analyst | London | Active | |
| Member 9 | Engineer | Oslo | Active | |
| Member 10 | Designer | Tokyo | Active | |
| Member 11 | Manager | Seattle | Active | |
| Member 12 | Analyst | New York | Active | |
| Member 13 | Engineer | London | Active | |
| Member 14 | Designer | Oslo | On leave | |
| Member 15 | Manager | Tokyo | Active | |
| Member 16 | Analyst | Seattle | Active | |
| Member 17 | Engineer | New York | Active | |
| Member 18 | Designer | London | Active | |
| Member 19 | Manager | Oslo | Active | |
| Member 20 | Analyst | Tokyo | Active |
export const Paging: Story = {
args: {
'aria-label': 'Team members, paged',
selectionMode: 'multiple',
},
render: (args) => <PagedGrid {...args} />,
};Resizable
| Status | |||
|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active |
| Bob Smith | Designer | New York | Active |
| Carol White | Manager | London | On leave |
| David Brown | Analyst | Oslo | Active |
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 Johnson | Engineer | Seattle | Active |
| Bob Smith | Designer | New York | Active |
| Carol White | Manager | London | On leave |
| David Brown | Analyst | Oslo | Active |
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 00001 | Engineer | Seattle | Active | |
| Member 00002 | Analyst | London | Active | |
| Member 00003 | Manager | Tokyo | Active | |
| Member 00004 | Designer | New York | Active | |
| Member 00005 | Engineer | Oslo | On leave | |
| Member 00006 | Analyst | Seattle | Active | |
| Member 00007 | Manager | London | Active | |
| Member 00008 | Designer | Tokyo | Active | |
| Member 00009 | Engineer | New York | Active | |
| Member 00010 | Analyst | Oslo | Active | |
| Member 00011 | Manager | Seattle | Active | |
| Member 00012 | Designer | London | Active | |
| Member 00013 | Engineer | Tokyo | Active | |
| Member 00014 | Analyst | New York | On leave | |
| Member 00015 | Manager | Oslo | Active | |
| Member 00016 | Designer | Seattle | Active | |
| Member 00017 | Engineer | London | Active |
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 Johnson | Engineer | Seattle | Active | |
| Bob Smith | Designer | New York | Active | |
| Carol White | Manager | London | On leave | |
| David Brown | Analyst | Oslo | Active |
| Status | ||||
|---|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active | |
| Bob Smith | Designer | New York | Active | |
| Carol White | Manager | London | On leave | |
| David Brown | Analyst | Oslo | Active |
| Status | ||||
|---|---|---|---|---|
| Alice Johnson | Engineer | Seattle | Active | |
| Bob Smith | Designer | New York | Active | |
| Carol White | Manager | London | On leave | |
| David Brown | Analyst | Oslo | Active |
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
| Role | Location | ||
|---|---|---|---|
| Alice Johnson | Seattle | ||
| Bob Smith | New York | ||
| Carol White | London | ||
| David Brown | Oslo |
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
| Role | Location | |
|---|---|---|
| Alice Johnson | Seattle | |
| Bob Smith | New York | |
| Carol White | London | |
| David Brown | Oslo |
export const CellFocusModes: Story = {
render: (args) => <FocusGrid {...args} cellFocusMode />,
};Footer Rows
| Status | |||
|---|---|---|---|
| Member 00001 | Engineer | Seattle | Active |
| Member 00002 | Analyst | London | Active |
| Member 00003 | Manager | Tokyo | Active |
| Member 00004 | Designer | New York | Active |
| Member 00005 | Engineer | Oslo | On leave |
| Member 00006 | Analyst | Seattle | Active |
| Member 00007 | Manager | London | Active |
| Member 00008 | Designer | Tokyo | Active |
| Member 00009 | Engineer | New York | Active |
| Member 00010 | Analyst | Oslo | Active |
| Member 00011 | Manager | Seattle | Active |
| Member 00012 | Designer | London | Active |
| Member 00013 | Engineer | Tokyo | Active |
| Member 00014 | Analyst | New York | On leave |
| Member 00015 | Manager | Oslo | Active |
| Member 00016 | Designer | Seattle | Active |
| Member 00017 | Engineer | London | Active |
| 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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
size | 'medium' | 'small' | 'extra-small' | No | 'medium' | The density of the grid: |
focusMode | 'cell' | 'row' | 'none' | No | 'cell' | How focus moves in the grid. |
getRowId | (item: T) => string | No | the item's index in `items`, as a string | The row id of an item: the |
isSelectionDisabled | (item: T, index: number) => boolean | No | Whether the selection of an item of | |
columns | readonly DataGridColumn<T>[] | No | Column definitions. When given and no | |
resizableColumns | boolean | No | false | Gives the header cell of each column (of |
columnSizingOptions | Record<string, ColumnSizingOption> | No | The sizing of each column, by | |
columnWidths | Record<string, number> | No | The column widths in pixels (controlled), by | |
defaultColumnWidths | Record<string, number> | No | The column widths in pixels at first render (uncontrolled; see | |
onColumnWidthsChange | (widths: Record<string, number>, details: TableColumnWidthsChangeDetails) => void | No | Called with the width of every column (by | |
virtualWindow | VirtualWindow | No | Renders only the body rows in view, plus an overscan, of a grid with many The grid's scroll wrapper (the element of 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 Needs | |
selectionMode | 'none' | 'single' | 'multiple' | No | 'none' | Row selection mode. |
labels | DataGridLabels | No | The grid's built-in text, for localization: the name of the select-all checkbox ( | |
selectOnRowClick | boolean | No | false | 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 |
selectionAppearance | 'brand' | 'neutral' | 'none' | No | 'brand' | How a selected row is filled: |
subtleSelection | boolean | No | false | 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 |
selectedItems | readonly string[] | No | Controlled selected row ids ( | |
defaultSelectedItems | readonly string[] | No | Initially selected row ids (uncontrolled). In single mode, at most one (see | |
onSelectedItemsChange | (selectedItems: string[], details: DataGridSelectedItemsChangeDetails) => void | No | Called with the new selected row ids when the selection changes, then With Without | |
containerProps | Omit<React.ComponentPropsWithRef<'div'>, 'children'> | No | Props for the wrapper | |
children | React.ReactNode | No | DataGrid header, body, and row elements. Optional when | |
ref | React.Ref<HTMLTableElement> | No | Ref to the | |
items | readonly T[] | No | The grid's data, one body row per item, in this order unless the sorted column has | |
sort | DataGridSort | null | No | The controlled sort, or | |
defaultSort | DataGridSort | null | No | Initial sort while | |
onSortChange | (sort: DataGridSort, details: DataGridSortChangeDetails) => void | No | Called with the new sort when a sortable header is activated (or |
Any other prop is passed to the element it renders (HTMLTableElement).
Parts
DataGrid.HeaderDataGrid.HeaderCellDataGrid.BodyDataGrid.RowDataGrid.CellDataGrid.SelectionCell
Stable class names
| Part | Class |
|---|---|
root | wave-data-grid |
container | wave-data-grid__container |
spacer | wave-data-grid__spacer |