Back to Reui

Data Grid

content/docs/components/base/data-grid.mdx

2.0.024.1 KB
Original Source

<ComponentPreview styleName="base-nova" name="c-data-grid-1" className="**:[.preview]:h-auto" align="start" />

The current data-grid package ships the shared grid context, table renderers, pagination, column controls, drag-and-drop helpers, virtualization, infinite scroll, footer helpers, and row-pinning support. Footer components (DataGridTableFoot, DataGridTableFootRow, DataGridTableFootRowCell) and the DataGridTableRowPin toggle are exported from data-grid-table.tsx.

In the base build, data-grid-scroll-area.tsx is also included and exports DataGridScrollArea for dedicated scroll handling around sticky-header or wide tables.

Installation

<CodeTabs> <TabsList> <TabsTrigger value="cli">CLI</TabsTrigger> <TabsTrigger value="manual">Manual</TabsTrigger> </TabsList> <TabsContent value="cli">
bash
npx shadcn@latest add @reui/data-grid
</TabsContent> <TabsContent value="manual"> <Steps>

<Step>Install the shared core dependencies:</Step>

bash
npm install @tanstack/react-table class-variance-authority

To enable drag-and-drop column or row reordering, install:

bash
npm install @dnd-kit/core @dnd-kit/modifiers @dnd-kit/sortable @dnd-kit/utilities

To enable virtualization and infinite scroll, install:

bash
npm install @tanstack/react-virtual

To use the dedicated scroll wrapper (DataGridScrollArea), install:

bash
npm install @base-ui/react

<Step>Copy the shipped files you need into your project.</Step>

data-grid-table.tsx exports the footer helpers and DataGridTableRowPin. data-grid-table-virtual.tsx adds virtualization, infinite scroll, and footerContent support. data-grid-scroll-area.tsx provides the dedicated base scroll wrapper.

<ComponentSource styleName="base-nova" name="data-grid" title="components/reui/data-grid/data-grid.tsx" />

<ComponentSource styleName="base-nova" name="data-grid-table" title="components/reui/data-grid/data-grid-table.tsx" />

<ComponentSource styleName="base-nova" name="data-grid-pagination" title="components/reui/data-grid/data-grid-pagination.tsx" />

<ComponentSource styleName="base-nova" name="data-grid-column-header" title="components/reui/data-grid/data-grid-column-header.tsx" />

<ComponentSource styleName="base-nova" name="data-grid-column-filter" title="components/reui/data-grid/data-grid-column-filter.tsx" />

<ComponentSource styleName="base-nova" name="data-grid-column-visibility" title="components/reui/data-grid/data-grid-column-visibility.tsx" />

<ComponentSource styleName="base-nova" name="data-grid-table-dnd" title="components/reui/data-grid/data-grid-table-dnd.tsx" />

<ComponentSource styleName="base-nova" name="data-grid-table-dnd-rows" title="components/reui/data-grid/data-grid-table-dnd-rows.tsx" />

<ComponentSource styleName="base-nova" name="data-grid-table-virtual" title="components/reui/data-grid/data-grid-table-virtual.tsx" />

<ComponentSource styleName="base-nova" name="data-grid-scroll-area" title="components/reui/data-grid/data-grid-scroll-area.tsx" />

<Step>Update the import paths to match your project setup.</Step>

</Steps> </TabsContent> </CodeTabs>

Usage

tsx
import {
  DataGrid,
  DataGridContainer,
  DataGridPagination,
  DataGridTable,
  DataGridTableFootRow,
  DataGridTableFootRowCell,
} from "@/components/reui/data-grid"
tsx
const footer = (
  <DataGridTableFootRow>
    <DataGridTableFootRowCell colSpan={columns.length}>
      Showing {data.length} rows
    </DataGridTableFootRowCell>
  </DataGridTableFootRow>
)

const table = useReactTable({
  data,
  columns,
  getCoreRowModel: getCoreRowModel(),
})

return (
  <DataGrid
    table={table}
    recordCount={data.length}
    tableLayout={{ rowsPinnable: true }}
  >
    <DataGridContainer>
      <DataGridTable footerContent={footer} />
    </DataGridContainer>
    <DataGridPagination />
  </DataGrid>
)

Use DataGridTableRowPin inside a column definition to let users pin rows, swap in DataGridTableVirtual when you need virtualization or infinite scroll, and wrap sticky-header tables with DataGridScrollArea when you want the dedicated base scroll wrapper. When rows can be pinned or virtualized, provide a stable getRowId so row identity stays intact across reordering.

Examples

Cell Border

<ComponentPreview styleName="base-nova" name="c-data-grid-2" className="**:[.preview]:h-auto" align="start" />

Dense Table

<ComponentPreview styleName="base-nova" name="c-data-grid-3" className="**:[.preview]:h-auto" align="start" />

Light Table

<ComponentPreview styleName="base-nova" name="c-data-grid-4" className="**:[.preview]:h-auto" align="start" />

Striped Table

<ComponentPreview styleName="base-nova" name="c-data-grid-5" className="**:[.preview]:h-auto" align="start" />

Auto Width

<ComponentPreview styleName="base-nova" name="c-data-grid-6" className="**:[.preview]:h-auto" align="start" />

Row Selection

<ComponentPreview styleName="base-nova" name="c-data-grid-7" className="**:[.preview]:h-auto" align="start" />

Expandable Row

<ComponentPreview styleName="base-nova" name="c-data-grid-8" className="**:[.preview]:h-auto" align="start" />

Sub Data Grid

<ComponentPreview styleName="base-nova" name="c-data-grid-9" className="**:[.preview]:h-auto" align="start" />

Column Icons

<ComponentPreview styleName="base-nova" name="c-data-grid-10" className="**:[.preview]:h-auto" align="start" />

Sortable Columns

<ComponentPreview styleName="base-nova" name="c-data-grid-11" className="**:[.preview]:h-auto" align="start" />

Movable Columns

<ComponentPreview styleName="base-nova" name="c-data-grid-12" className="**:[.preview]:h-auto" align="start" />

Draggable Columns

<ComponentPreview styleName="base-nova" name="c-data-grid-13" className="**:[.preview]:h-auto" align="start" />

Draggable Rows

<ComponentPreview styleName="base-nova" name="c-data-grid-14" className="**:[.preview]:h-auto" align="start" />

Resizable Columns

<ComponentPreview styleName="base-nova" name="c-data-grid-15" className="**:[.preview]:h-auto" align="start" />

Pinnable Columns

<ComponentPreview styleName="base-nova" name="c-data-grid-16" className="**:[.preview]:h-auto" align="start" />

<ComponentPreview styleName="base-nova" name="c-data-grid-17" className="**:[.preview]:h-auto" align="start" />

Column Controls

<ComponentPreview styleName="base-nova" name="c-data-grid-18" className="**:[.preview]:h-auto" align="start" />

Card Container

<ComponentPreview styleName="base-nova" name="c-data-grid-19" className="**:[.preview]:h-auto" align="start" />

Column Visibility

<ComponentPreview styleName="base-nova" name="c-data-grid-20" className="**:[.preview]:h-auto" align="start" />

Loading Skeleton

<ComponentPreview styleName="base-nova" name="c-data-grid-21" className="**:[.preview]:h-auto" align="start" />

CRUD

<ComponentPreview styleName="base-nova" name="c-data-grid-22" className="**:[.preview]:h-auto" align="start" />

CRUD in Frame

<ComponentPreview styleName="base-nova" name="c-data-grid-23" className="**:[.preview]:h-auto" align="start" />

<ComponentPreview styleName="base-nova" name="c-data-grid-24" className="**:[.preview]:h-auto" align="start" />

<ComponentPreview styleName="base-nova" name="c-data-grid-25" className="**:[.preview]:h-auto" align="start" />

<ComponentPreview styleName="base-nova" name="c-data-grid-26" className="**:[.preview]:h-auto" align="start" />

Infinite Scroll (Local)

<ComponentPreview styleName="base-nova" name="c-data-grid-27" className="**:[.preview]:h-auto" align="start" />

Infinite Scroll (Remote)

<ComponentPreview styleName="base-nova" name="c-data-grid-28" className="**:[.preview]:h-auto" align="start" />

Row Pinning

<ComponentPreview styleName="base-nova" name="c-data-grid-29" className="**:[.preview]:h-auto" align="start" />

API Reference

DataGrid

The root component that provides the table context.

PropTypeDefaultDescription
tableTable<TData>-Required. The TanStack Table instance.
recordCountnumber-Required. Total number of records.
isLoadingbooleanfalseWhether the table is in a loading state.
loadingMode"skeleton" | "spinner""skeleton"The visual style of the loading state.
loadingMessageReactNode | string"Loading..."Message to display when loadingMode is "spinner".
fetchingMoreMessageReactNode | stringloadingMessageMessage to display while DataGridTableVirtual is fetching more rows.
allRowsLoadedMessageReactNode | string"All records loaded"Message to display when virtual infinite scroll reaches the end.
emptyMessageReactNode | string"No data available"Message to display when the table is empty.
onRowClick(row: TData) => void-Callback function triggered when a row is clicked.
tableLayoutDataGridTableLayout-Configuration for table layout and features.
tableClassNamesDataGridTableClassNames-Custom CSS classes for various table parts.
classNamestring-Additional CSS classes for the root grid component.

DataGridTableLayout

Configuration object for the table's behavior and appearance.

PropertyTypeDefaultDescription
densebooleanfalseWhether to use dense padding for cells.
cellBorderbooleanfalseWhether to show vertical borders between cells.
rowBorderbooleantrueWhether to show horizontal borders between rows.
rowRoundedbooleanfalseWhether to add rounded corners to rows.
strippedbooleanfalseWhether to use zebra-striping for rows.
headerBackgroundbooleantrueWhether to show a background color for the header.
headerBorderbooleantrueWhether to show a border below the header.
headerStickybooleanfalseWhether the header should be sticky during scroll.
width"auto" | "fixed""fixed"The table layout algorithm (table-auto vs table-fixed).
columnsVisibilitybooleanfalseEnables column visibility toggling.
columnsResizablebooleanfalseEnables column resizing.
columnsPinnablebooleanfalseEnables column pinning.
columnsMovablebooleanfalseEnables moving columns via menu.
columnsDraggablebooleanfalseEnables drag-and-drop for columns.
rowsDraggablebooleanfalseEnables drag-and-drop for rows.
rowsPinnablebooleanfalseEnables row pinning (top/bottom).

DataGridTableClassNames

Custom CSS classes for different parts of the table.

PropertyTypeDefaultDescription
basestring-CSS classes for the <table> element.
headerstring-CSS classes for the <thead> element.
headerRowstring-CSS classes for header rows.
headerStickystring-CSS classes for sticky header state.
bodystring-CSS classes for the <tbody> element.
bodyRowstring-CSS classes for body rows.
footerstring-CSS classes for the <tfoot> element.
edgeCellstring-CSS classes for the first and last cells in a row.

DataGridContainer

A scrollable container for the table.

PropTypeDefaultDescription
borderbooleantrueWhether to show a border around the container.
classNamestring-Additional CSS classes for the container.

DataGridScrollArea

Dedicated scroll wrapper for wide grids and sticky headers.

PropTypeDefaultDescription
childrenReactNode-Required. The grid content to wrap.
orientation"horizontal" | "vertical" | "both""both"Which scrollbars to render.
classNamestring-Additional CSS classes for the wrapper.

DataGridTable

The component that renders the actual HTML table. It automatically handles data rendering, loading states (skeletons/spinners), empty states, footer rows, and pinned rows when rowsPinnable is enabled on the parent DataGrid.

PropTypeDefaultDescription
footerContentReactNode-Optional footer content rendered inside <tfoot>.
renderHeaderbooleantrueWhether to render the table header.

DataGridPagination

The component for table pagination controls.

PropTypeDefaultDescription
sizesnumber[][5, 10, 25, 50, 100]Array of available page sizes.
sizesLabelstring"Show"Label for the page size selector.
sizesDescriptionstring"per page"Description following the page size selector.
rowsPerPageLabelstring"Rows per page"Accessible label for the rows per page selector.
infostring"{from} - {to} of {count}"Template for displaying record info.
morebooleanfalseWhether to show ellipsis for more pages.
moreLimitnumber5The number of page buttons to show before truncating.
previousPageLabelstring"Go to previous page"Accessible label for the previous page button.
nextPageLabelstring"Go to next page"Accessible label for the next page button.
ellipsisTextstring"..."Text to display for the ellipsis button.
classNamestring-Additional CSS classes for the pagination container.

DataGridColumnHeader

A flexible column header component with built-in support for sorting, pinning, and moving columns.

PropTypeDefaultDescription
columnColumn<TData, TValue>-Required. The TanStack Column instance.
titlestring-The title to display in the header.
iconReactNode-Optional icon to display next to the title.
filterReactNode-Optional filter component to display in the header menu.
visibilitybooleanfalseWhether to include column visibility controls in the menu.

DataGridColumnFilter

A popover-based multi-select filter for columns.

PropTypeDefaultDescription
columnColumn<TData, TValue>-The TanStack Column instance to filter.
titlestring-The title for the filter trigger and placeholder.
optionsArray<{ label: string, value: string, icon?: ComponentType }>-Required. The list of options to filter by.

DataGridColumnVisibility

A dropdown component to toggle column visibility.

PropTypeDefaultDescription
tableTable<TData>-Required. The TanStack Table instance.
triggerReactElement-Required. The trigger element for the visibility menu.

DataGridTableDnd

Used for enabling column drag-and-drop reordering with optional footer rendering.

PropTypeDefaultDescription
handleDragEnd(event: DragEndEvent) => void-Required. Callback triggered when a column drag operation ends.
footerContentReactNode-Optional footer content rendered inside <tfoot>.

DataGridTableDndRows

Used for enabling row drag-and-drop reordering with optional footer rendering.

PropTypeDefaultDescription
dataIdsUniqueIdentifier[]-Required. Array of unique identifiers for the current page data.
handleDragEnd(event: DragEndEvent) => void-Required. Callback triggered when a row drag operation ends.
footerContentReactNode-Optional footer content rendered inside <tfoot>.

DataGridTableVirtual

A virtualized table renderer using @tanstack/react-virtual for row virtualization, infinite scroll, optional footer rows, and pinned rows when rowsPinnable is enabled. The wrapper manages row count and the scroll element for you, while virtualizerOptions lets you customize the underlying TanStack Virtual instance.

PropTypeDefaultDescription
heightnumber | string-Optional fixed height when not using an outer scroll container.
estimateSizenumber48Estimated row height in pixels for the virtualizer.
overscannumber10Number of rows to render outside the visible area.
footerContentReactNode-Optional footer content rendered inside <tfoot>.
renderHeaderbooleantrueWhether to render the table header.
onFetchMore() => void-Callback triggered when user scrolls near the bottom.
isFetchingMoreboolean-Whether additional data is currently being loaded.
hasMoreboolean-Whether there are more records available to fetch.
fetchMoreOffsetnumber0How many rows before the end should trigger onFetchMore.
virtualizerOptionsDataGridTableVirtualizerOptions<TData>-Optional passthrough for TanStack Virtual settings like enabled, getItemKey, measureElement, rangeExtractor, and onChange.

DataGridTableRowPin

A pin/unpin toggle button for use in column definitions to enable row pinning.

PropTypeDefaultDescription
rowRow<TData>-Required. The TanStack Table row instance.

DataGridTableFoot

Wrapper component for the table footer (<tfoot>).


DataGridTableFootRow

A row inside the table footer.


DataGridTableFootRowCell

A cell inside a footer row.

PropTypeDefaultDescription
colSpannumber-Column span for the footer cell.
classNamestring-Additional CSS classes.
childrenReactNode-Content of the footer cell.