Next Chapter Begins 🚀Read the full story

DataTable

DataTable displays tabular data with sorting, pagination, selection and filtering features.

ProductCategoryPriceStatus

Fetching products

Hang tight, your data will appear here in a moment.

Installation#

npx shadcn@latest add https://primereact.dev/r/datatable.json

Usage#

import {
    DataTable,
    DataTableCell,
    DataTableHeader,
    DataTableFooter,
    DataTableRow,
    DataTableSort,
    DataTableSortIndicator,
    DataTableSortOrder,
    DataTableTBody,
    DataTableTHead,
    DataTableTHeadCell,
    DataTableTHeadRow,
    DataTableTable,
    DataTableTableContainer,
    DataTablePagination
} from '@/components/ui/datatable';
<DataTable data={items}>
    <DataTableTableContainer>
        <DataTableTable>
            <DataTableTHead>
                <DataTableTHeadRow>
                    <DataTableTHeadCell>Column</DataTableTHeadCell>
                </DataTableTHeadRow>
            </DataTableTHead>
            <DataTableTBody>
                {({ item }) => (
                    <DataTableRow>
                        <DataTableCell>{item.name}</DataTableCell>
                    </DataTableRow>
                )}
            </DataTableTBody>
        </DataTableTable>
    </DataTableTableContainer>
</DataTable>

Examples#

Basic#

Displays a list of items in tabular format.

basic-demo

Striped Rows#

Use the stripedRows prop to render rows with alternating background colors.

striped-demo

Selection#

Row selection is driven by the selectionMode prop (single or multiple). The selectionKeys prop holds a map of selected row keys and onSelectionChange fires when the selection changes.

Single#

One row at a time. Clicking a different row replaces the previous selection.

single-selection-demo

Multiple#

Multiple rows without a dedicated column. Pair with metaKeySelection so Ctrl/Cmd + Click toggles rows and Shift + Click selects a range.

multiple-selection-demo

Checkbox#

Checkbox-based multiple selection with a header select-all.

checkbox-selection-demo

Keyboard#

Arrow Up/Down moves focus between rows, Space or Enter toggles the focused row, and Shift + Arrow extends a range.

keyboard-demo

Sort#

Wrap a column header with DataTableSort field="…" to make it sortable. DataTableSortIndicator match="asc | desc | unsorted" renders direction icons and DataTableSortOrder shows the priority badge in multi-sort mode.

Single#

Clicking a column header cycles through ascending, descending and unsorted.

sort-demo

Multiple#

Hold Ctrl/Cmd and click multiple column headers to sort by several fields at once.

multisort-demo

Presort#

Apply an initial sort on mount via defaultSortField + defaultSortOrder.

presort-demo

For multi-column presort, use defaultMultiSortMeta.

presort-multi-demo

Pagination#

DataTable exposes pagination state via render prop, allowing complete control over the pagination UI.

pagination-demo

Scroll#

Set scrollable on DataTable to enable scrolling.

Horizontal#

When the combined column widths exceed the container, the table scrolls horizontally.

scroll-horizontal-demo

Frozen Columns#

Pin multiple columns to either side using frozen and frozenAlignment.

scroll-frozen-columns-multi-demo

Frozen Rows#

Render a DataTableFrozenTBody above the regular DataTableTBody to keep specific rows pinned to the top.

scroll-frozen-rows-demo

Row Expansion#

Expand rows to show additional detail content.

expansion-demo

Column Resize#

Enable column resizing with drag handles via the resizableColumns prop.

Fit Mode#

Dragging takes width from the adjacent column; total table width stays the same.

resize-demo

Expand Mode#

Dragging grows or shrinks the whole table; adjacent columns keep their widths.

resize-expand-demo

Column Reorder#

Drag and drop column headers to reorder columns.

reorder-demo

Row Reorder#

Drag and drop rows to reorder data.

row-reorder-demo

Column Group#

Multi-level headers with rowspan and colspan.

column-group-demo

Sort and filter work on any leaf header cell in a grouped layout.

column-group-filter-sort-demo

Filter#

Filtering is driven by a filters object passed to DataTable. Global search is opt-in via globalFilter + globalFilterFields.

filter-demo

Use DataTableHeader and DataTableFooter to add summary information above and below the table.

template-demo

Export#

Export table data to CSV with customizable fields and headers.

export-demo

Loading#

Overlay#

Set the loading prop on DataTable and provide a spinner inside DataTableLoading. An absolutely positioned overlay dims the table.

loading-overlay-demo

Skeleton#

Render placeholder rows filled with Skeleton elements while the request is in flight.

loading-skeleton-demo

Empty State#

Custom empty state when no data is available, using EmptyTBody.

empty-demo

Sub-Components#

See DataTable Primitive for the full sub-component API.

Hooks#

See useDataTable for the headless hook API.

Accessibility#

See DataTable Primitive for WAI-ARIA compliance details and keyboard support.