Data Table
An interactive Shadcn data table with stable sorting, global and column filtering, column visibility, pagination, and row selection.
An interactive data table built over semantic table structure with stable sorting, global and per-column filtering, column visibility, pagination, and row or page selection. The examples on this page use the Shadcn Rhea style preset.
Preview
Section titled “Preview”<div class="grid w-full max-w-2xl gap-4">
<div class="flex flex-wrap items-center justify-between gap-2">
<proto-ui-shadcn-input-root
id="email-filter"
class="w-full max-w-xs"
></proto-ui-shadcn-input-root>
<div class="flex gap-2">
<proto-ui-shadcn-button id="toggle-status">
Toggle Status
</proto-ui-shadcn-button>
<proto-ui-shadcn-button id="select-page">
Select page
</proto-ui-shadcn-button>
</div>
</div>
<proto-ui-shadcn-data-table-root
id="payments-table"
class="rounded-md border border-border"
>
<proto-ui-shadcn-data-table-caption>
Recent payments.
</proto-ui-shadcn-data-table-caption>
<proto-ui-shadcn-data-table-header-row>
<proto-ui-shadcn-data-table-header data-key="status">
Status
</proto-ui-shadcn-data-table-header>
<proto-ui-shadcn-data-table-header data-key="email">
Email
</proto-ui-shadcn-data-table-header>
<proto-ui-shadcn-data-table-header
data-key="amount"
class="text-right"
>
Amount
</proto-ui-shadcn-data-table-header>
</proto-ui-shadcn-data-table-header-row>
<proto-ui-shadcn-data-table-row data-index="0">
<proto-ui-shadcn-data-table-cell
data-col="status"
></proto-ui-shadcn-data-table-cell>
<proto-ui-shadcn-data-table-cell
data-col="email"
></proto-ui-shadcn-data-table-cell>
<proto-ui-shadcn-data-table-cell
data-col="amount"
class="text-right font-medium"
></proto-ui-shadcn-data-table-cell>
</proto-ui-shadcn-data-table-row>
<div class="table-caption caption-bottom">
<div class="flex items-center justify-between pt-3">
<span id="summary" class="text-sm text-muted-foreground">
0 of 5 row(s) selected.
</span>
<div class="flex gap-2">
<proto-ui-shadcn-data-table-previous>
Previous
</proto-ui-shadcn-data-table-previous>
<proto-ui-shadcn-data-table-next>
Next
</proto-ui-shadcn-data-table-next>
</div>
</div>
</div>
</proto-ui-shadcn-data-table-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const rows = [
{
id: 'm5gr84i9',
status: 'Success',
email: 'ken99@example.com',
amount: 316,
},
{
id: '3u1reuv4',
status: 'Success',
email: 'abe45@example.com',
amount: 242,
},
{
id: 'derv1ws0',
status: 'Processing',
email: 'monserrat44@example.com',
amount: 837,
},
{
id: '5kma53ae',
status: 'Success',
email: 'silas22@example.com',
amount: 874,
},
{
id: 'bhqecj4p',
status: 'Failed',
email: 'carmella@example.com',
amount: 721,
},
];
const table = document.querySelector('#payments-table');
setElementProps(table, {
styleProfile: 'rhea',
rows,
pageSize: 4,
});
setElementProps(document.querySelector('#email-filter'), {
styleProfile: 'rhea',
placeholder: 'Filter emails...',
onValueChange: ({ value }) =>
setElementProps(table, { columnFilters: { email: value } }),
});
</script>Installation
Section titled “Installation”Available starting in 0.3.0-rc.1 and later releases.
import { ShadcnDataTableCaption, ShadcnDataTableCell, ShadcnDataTableHeader, ShadcnDataTableHeaderRow, ShadcnDataTableNext, ShadcnDataTablePrevious, ShadcnDataTableRoot, ShadcnDataTableRow,} from '../proto-ui/components/react';
const rows = [ { id: 'm5gr84i9', status: 'Success', email: 'ken99@example.com', amount: 316 }, { id: '3u1reuv4', status: 'Success', email: 'abe45@example.com', amount: 242 },];
export function Example() { return ( <ShadcnDataTableRoot rows={rows} pageSize={4} className="rounded-md border border-border"> <ShadcnDataTableCaption>Recent payments.</ShadcnDataTableCaption> <ShadcnDataTableHeaderRow> <ShadcnDataTableHeader headerKey="status">Status</ShadcnDataTableHeader> <ShadcnDataTableHeader headerKey="email">Email</ShadcnDataTableHeader> <ShadcnDataTableHeader headerKey="amount" className="text-right"> Amount </ShadcnDataTableHeader> </ShadcnDataTableHeaderRow> {[0, 1].map((index) => ( <ShadcnDataTableRow key={index} index={index}> <ShadcnDataTableCell columnKey="status" headers={['status']} /> <ShadcnDataTableCell columnKey="email" headers={['email']} /> <ShadcnDataTableCell columnKey="amount" headers={['amount']} className="text-right" /> </ShadcnDataTableRow> ))} <div className="table-caption caption-bottom"> <div className="flex justify-end gap-2 pt-3"> <ShadcnDataTablePrevious>Previous</ShadcnDataTablePrevious> <ShadcnDataTableNext>Next</ShadcnDataTableNext> </div> </div> </ShadcnDataTableRoot> );}Structure & Accessibility
Section titled “Structure & Accessibility”- Record identity and row slots: Every record in
rowsrequires a unique non-emptyid. Body slots (DataTableRow) map to the active page byindex, and eachDataTableCellrenders the matchingcolumnKeyso sorting and paging update real table content. - Headers and keyboard interaction: Place sortable column headers inside passive
DataTableHeaderRowcontainers. PressingEnterorSpaceon a focused sortable header cycles sorting, and on a focused row toggles selection. - Style presets (
styleProfile): Supportsvega,nova,maia,lyra,mira,luma,sera,rhea, andnew-york-v4; omitting it or settinginheritfollows the nearestStyle Scopebefore falling back to the default profile.
Examples
Section titled “Examples”Basic Table & Sorting
Section titled “Basic Table & Sorting”Set sortable={false} on non-sortable columns and configure initial sorting with defaultSortKey and defaultSortDirection.
<proto-ui-shadcn-data-table-root
id="basic-table"
class="rounded-md border border-border"
>
<proto-ui-shadcn-data-table-caption>
A list of your recent invoices.
</proto-ui-shadcn-data-table-caption>
<proto-ui-shadcn-data-table-header-row>
<proto-ui-shadcn-data-table-header>
Invoice
</proto-ui-shadcn-data-table-header>
<proto-ui-shadcn-data-table-header>
Status
</proto-ui-shadcn-data-table-header>
<proto-ui-shadcn-data-table-header>
Method
</proto-ui-shadcn-data-table-header>
<proto-ui-shadcn-data-table-header class="text-right">
Amount (USD)
</proto-ui-shadcn-data-table-header>
</proto-ui-shadcn-data-table-header-row>
<proto-ui-shadcn-data-table-row>
<proto-ui-shadcn-data-table-cell></proto-ui-shadcn-data-table-cell>
<proto-ui-shadcn-data-table-cell></proto-ui-shadcn-data-table-cell>
<proto-ui-shadcn-data-table-cell></proto-ui-shadcn-data-table-cell>
<proto-ui-shadcn-data-table-cell
class="text-right font-medium"
></proto-ui-shadcn-data-table-cell>
</proto-ui-shadcn-data-table-row>
</proto-ui-shadcn-data-table-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#basic-table'), {
styleProfile: 'rhea',
defaultSortKey: 'invoice',
defaultSortDirection: 'ascending',
pageSize: 4,
rows: [
{
id: 'inv-001',
invoice: 'INV001',
status: 'Paid',
method: 'Credit Card',
amount: 250,
},
{
id: 'inv-002',
invoice: 'INV002',
status: 'Pending',
method: 'PayPal',
amount: 150,
},
],
});
</script>Filtering & Column Visibility
Section titled “Filtering & Column Visibility”Combine global filter with per-column columnFilters, and toggle columns with columnVisibility while preserving element identity and table structure.
<div class="grid gap-3">
<div class="flex flex-wrap gap-2">
<proto-ui-shadcn-input-root
id="global-filter"
></proto-ui-shadcn-input-root>
<proto-ui-shadcn-input-root
id="status-filter"
></proto-ui-shadcn-input-root>
<proto-ui-shadcn-button id="toggle-method">
Toggle Method
</proto-ui-shadcn-button>
</div>
<proto-ui-shadcn-data-table-root
id="filter-table"
class="rounded-md border border-border"
>
<proto-ui-shadcn-data-table-header-row>
<proto-ui-shadcn-data-table-header>
Invoice
</proto-ui-shadcn-data-table-header>
<proto-ui-shadcn-data-table-header>
Status
</proto-ui-shadcn-data-table-header>
<proto-ui-shadcn-data-table-header>
Method
</proto-ui-shadcn-data-table-header>
</proto-ui-shadcn-data-table-header-row>
</proto-ui-shadcn-data-table-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const table = document.querySelector('#filter-table');
let showMethod = true;
setElementProps(document.querySelector('#global-filter'), {
styleProfile: 'rhea',
placeholder: 'Search all...',
onValueChange: ({ value }) =>
setElementProps(table, { filter: value }),
});
setElementProps(document.querySelector('#status-filter'), {
styleProfile: 'rhea',
placeholder: 'Status...',
onValueChange: ({ value }) =>
setElementProps(table, { columnFilters: { status: value } }),
});
setElementProps(document.querySelector('#toggle-method'), {
onClick: () => {
showMethod = !showMethod;
setElementProps(table, {
columnVisibility: { method: showMethod },
});
},
});
</script>Pagination & Row Selection
Section titled “Pagination & Row Selection”requestPageSelection() toggles only the current filtered page while preserving selections across other pages; DataTablePrevious and DataTableNext step through pages via table context.
<proto-ui-shadcn-data-table-root
id="paged-table"
class="rounded-md border border-border"
>
<proto-ui-shadcn-data-table-header-row>
<proto-ui-shadcn-data-table-header>
Invoice
</proto-ui-shadcn-data-table-header>
<proto-ui-shadcn-data-table-header>
Status
</proto-ui-shadcn-data-table-header>
<proto-ui-shadcn-data-table-header>
Method
</proto-ui-shadcn-data-table-header>
</proto-ui-shadcn-data-table-header-row>
<div class="table-caption caption-bottom">
<div class="flex items-center justify-end gap-2 pt-3">
<proto-ui-shadcn-data-table-previous>
Previous
</proto-ui-shadcn-data-table-previous>
<proto-ui-shadcn-data-table-next>
Next
</proto-ui-shadcn-data-table-next>
</div>
</div>
</proto-ui-shadcn-data-table-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#paged-table'), {
styleProfile: 'rhea',
pageSize: 3,
defaultSelectedKeys: ['inv-001'],
rows: [
{
id: 'inv-001',
invoice: 'INV001',
status: 'Paid',
method: 'Credit Card',
},
{
id: 'inv-002',
invoice: 'INV002',
status: 'Pending',
method: 'PayPal',
},
{
id: 'inv-003',
invoice: 'INV003',
status: 'Unpaid',
method: 'Bank Transfer',
},
{
id: 'inv-004',
invoice: 'INV004',
status: 'Paid',
method: 'Credit Card',
},
],
});
</script>Read-Only & Disabled States
Section titled “Read-Only & Disabled States”readOnly={true} locks row and page selection while keeping sorting and pagination interactive; disabled={true} disables all table interactions.
<proto-ui-shadcn-data-table-root
id="readonly-table"
class="rounded-md border border-border"
></proto-ui-shadcn-data-table-root>
<proto-ui-shadcn-data-table-root
id="disabled-table"
class="rounded-md border border-border"
></proto-ui-shadcn-data-table-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const rows = [
{
id: 'm5gr84i9',
status: 'Success',
email: 'ken99@example.com',
},
{
id: '3u1reuv4',
status: 'Success',
email: 'abe45@example.com',
},
];
setElementProps(document.querySelector('#readonly-table'), {
styleProfile: 'rhea',
rows,
readOnly: true,
});
setElementProps(document.querySelector('#disabled-table'), {
styleProfile: 'rhea',
rows,
disabled: true,
});
</script>Custom Cell Formatting Recipe
Section titled “Custom Cell Formatting Recipe”Set renderValue={false} on DataTableCell to render your own children and subscribe to displayValue for live formatted output.
<div class="grid w-full max-w-xl gap-3">
<proto-ui-shadcn-input-root
id="service-filter"
></proto-ui-shadcn-input-root>
<div class="flex flex-wrap gap-2">
<proto-ui-shadcn-button id="toggle-col">
Show / hide status
</proto-ui-shadcn-button>
<proto-ui-shadcn-button id="select-current-page">
Select / clear current page
</proto-ui-shadcn-button>
</div>
<proto-ui-shadcn-data-table-root id="recipes-table">
<proto-ui-shadcn-data-table-caption>
Service inventory
</proto-ui-shadcn-data-table-caption>
<proto-ui-shadcn-data-table-header-row>
<proto-ui-shadcn-data-table-header>
Service
</proto-ui-shadcn-data-table-header>
<proto-ui-shadcn-data-table-header>
Status
</proto-ui-shadcn-data-table-header>
</proto-ui-shadcn-data-table-header-row>
<proto-ui-shadcn-data-table-row>
<proto-ui-shadcn-data-table-cell></proto-ui-shadcn-data-table-cell>
<proto-ui-shadcn-data-table-cell id="custom-cell-0">
<span></span>
</proto-ui-shadcn-data-table-cell>
</proto-ui-shadcn-data-table-row>
<div class="flex gap-2">
<proto-ui-shadcn-data-table-previous>
Previous
</proto-ui-shadcn-data-table-previous>
<proto-ui-shadcn-data-table-next>
Next
</proto-ui-shadcn-data-table-next>
</div>
</proto-ui-shadcn-data-table-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#custom-cell-0'), {
columnKey: 'state',
headers: ['state'],
renderValue: false,
});
</script>Passing sortKey, sortDirection, page, or selectedKeys controls the corresponding state independently.
| Prop | Type | Default |
|---|---|---|
styleProfile | ShadcnStyleChoice | inherit → scope → nova |
rows | readonly DataRecord[] | [] |
sortKey | string | — (controlled) |
defaultSortKey | string | '' |
sortDirection | 'none' 'ascending' 'descending' | — (controlled) |
defaultSortDirection | 'none' 'ascending' 'descending' | 'none' |
filter | string | '' |
columnFilters | Readonly<Record<string, string>> | {} |
columnVisibility | Readonly<Record<string, boolean>> | {} |
page | number | — (controlled) |
defaultPage | number | 0 |
pageSize | number | 10 |
selectedKeys | readonly string[] | — (controlled) |
defaultSelectedKeys | readonly string[] | [] |
disabled | boolean | false |
readOnly | boolean | false |
Part Props
Section titled “Part Props”| Part / Prop | Type | Default |
|---|---|---|
HeaderRow.styleProfile | ShadcnStyleChoice | inherit → scope → nova |
Row.index | number | 0 |
Row.header | boolean | false |
Row.styleProfile | ShadcnStyleChoice | inherit → scope → nova |
Header.headerKey | string | '' |
Header.headerKind | 'column' 'row' | 'column' |
Header.sortable | boolean | true |
Header.styleProfile | ShadcnStyleChoice | inherit → scope → nova |
Cell.columnKey | string | '' |
Cell.headers | readonly string[] | [] |
Cell.renderValue | boolean | true |
Cell.styleProfile | ShadcnStyleChoice | inherit → scope → nova |
Previous / Next | ButtonProps & ShadcnStyleProps | outline action paint |
Events, Methods & Exposed States
Section titled “Events, Methods & Exposed States”- Events (Root):
sortChange({ sortKey, sortDirection }),pageChange({ page }),selectionChange({ selectedKeys }). - Methods (Root):
getRows(),getRecord(id),getSelectedKeys(),requestSort(key),requestPage(next),requestSelection(id),requestPageSelection(selected?). - Exposed States: Root exposes
filteredCountandpageSelection('none' | 'some' | 'all'); Row exposesrowKey,selected,focused, andfocusVisible; Header exposessort; Cell exposesdisplayValue.