Empty state
Show your own content, an illustration, a message or an action, in the body of a grid that has no rows.
A grid with no rows still renders its header. DataGrid.Empty renders its children in the body
area while there are no rows, and nothing once there are.
The part
Place Empty inside Grid, after the Header. It is a cell of its own (role="gridcell",
spanning every column) in a row of its own (role="row"), in an area right below the header, as
tall as the visible body and as wide as the columns (at most the visible body, the whole of it
without columns), so what you centre in it sits under the header, that stays in view when the grid scrolls sideways (wide columns still
scroll their header). Your class, style and children go on the cell; it has no text or name of
its own: what it says is yours.
<DataGrid.Root columns={columns} rows={rows}>
<DataGrid.Grid aria-label="People">
<DataGrid.Header />
<DataGrid.Body />
<DataGrid.Empty className="flex flex-col items-center justify-center gap-3">
<p>No people yet</p>
<button type="button" onClick={addSampleRows}>
Add sample rows
</button>
</DataGrid.Empty>
</DataGrid.Grid>
</DataGrid.Root>The cell is as tall as the area (a structural height and box-sizing), and its display is
yours: a flex column or a grid lays the content out, as above. The area (its part is
empty-area: sticky, as tall as the visible body, as wide as the columns in view) and the row (empty-row: a block as
tall as the area) are the grid's own elements, with structural style only: paint the cell, or
select them by their data-grid-part in CSS.
As a table
Inside a <table>, render Empty as a <td>: its row is a <tr> and its area a <tbody>, so
the markup stays valid, and the cell spans every column (colSpan). A table's cell is a block as
tall as the area; lay the content out in an element of yours inside it:
<DataGrid.Empty render={<td />}>
<div className="grid h-full place-items-center">No people yet</div>
</DataGrid.Empty>Styling the rest of the grid
Root and Grid carry data-empty while there are no rows, so any part can change with it. With
Tailwind, in-data-empty: styles an element inside an empty grid:
[data-grid-part="grid"][data-empty] [data-grid-part="header-row"] {
border-bottom-color: transparent;
}The keyboard
With no rows, nothing in the body can be active, and the grid stays a tab stop. Tabbing into
it focuses the first header cell. If a cell was active when the rows went away, the active
cell moves to the header cell of its column. Tab then reaches the controls inside Empty. An
action that brings rows back removes itself with the empty state: move focus to the grid (a ref
on Grid) in its handler, as the example does, so it is not lost.
The grid takes keys only from its cells, from itself and from its viewport. The arrows, Home,
End and Page keys pressed on a control inside Empty stay with that control.
Accessibility
Empty is a cell in a row of the grid (gridcell in a row, or a td in a tr), spanning
every column: a grid owns only rows, and its content belongs in one. While there are no rows,
the grid's aria-rowcount counts that row, and it carries its aria-rowindex, after the header
rows (and the top summary rows). It is no cell of the grid's
data (no indexes): the keys and the tab order leave its controls alone. Keep the message short
and the action a real button. To announce that the grid has
just been emptied, use a live region of your own, outside the grid.