Data Table

Data tables with search, sorting, filtering, row selection, pagination, and expandable detail rows for dashboards.

Loading preview

Examples

Practical examples and common states for the same installable component.

Sortable

Click column headers to sort rows ascending or descending.

examples/data-table-sortable.tsx
"use client";
import {
DataTable,
type DataTableColumn,
} from "@/components/wensity/data-table";
type Invoice = {
id: string;
customer: string;
plan: string;
amount: string;
status: string;
};
const columns: DataTableColumn<Invoice>[] = [
{ id: "customer", header: "Customer", accessorKey: "customer", sortable: true },
{ id: "plan", header: "Plan", accessorKey: "plan", sortable: true },
{ id: "amount", header: "Amount", accessorKey: "amount", sortable: true },
{ id: "status", header: "Status", accessorKey: "status", sortable: true },
];
export function SortableDataTable({ data }: { data: Invoice[] }) {
return <DataTable columns={columns} data={data} sortable />;
}

Filterable

Built-in search bar filters across all columns with debounced input.

examples/data-table-filterable.tsx
"use client";
import {
DataTable,
type DataTableColumn,
} from "@/components/wensity/data-table";
type Invoice = {
id: string;
customer: string;
plan: string;
status: string;
};
const columns: DataTableColumn<Invoice>[] = [
{ id: "customer", header: "Customer", accessorKey: "customer" },
{ id: "plan", header: "Plan", accessorKey: "plan" },
{ id: "status", header: "Status", accessorKey: "status" },
];
export function FilterableDataTable({ data }: { data: Invoice[] }) {
return (
<DataTable
columns={columns}
data={data}
filterable={{ placeholder: "Search invoices…" }}
/>
);
}

Selectable

Checkbox column with select-all and individual row selection.

examples/data-table-selectable.tsx
"use client";
import {
DataTable,
type DataTableColumn,
} from "@/components/wensity/data-table";
type User = {
id: string;
name: string;
role: string;
};
const columns: DataTableColumn<User>[] = [
{ id: "name", header: "Name", accessorKey: "name" },
{ id: "role", header: "Role", accessorKey: "role" },
];
export function SelectableDataTable({ data }: { data: User[] }) {
return <DataTable columns={columns} data={data} selectable />;
}

Paginated

Splits large datasets across pages with compact pagination controls.

examples/data-table-paginated.tsx
"use client";
import {
DataTable,
type DataTableColumn,
} from "@/components/wensity/data-table";
type Invoice = {
id: string;
customer: string;
plan: string;
amount: string;
status: string;
};
const columns: DataTableColumn<Invoice>[] = [
{ id: "customer", header: "Customer", accessorKey: "customer", sortable: true },
{ id: "plan", header: "Plan", accessorKey: "plan" },
{ id: "amount", header: "Amount", accessorKey: "amount", sortable: true },
{ id: "status", header: "Status", accessorKey: "status" },
];
export function PaginatedDataTable({ data }: { data: Invoice[] }) {
return (
<DataTable
columns={columns}
data={data}
sortable
paginated={{ pageSize: 5 }}
/>
);
}

Expandable

Click any row to reveal additional details in an expandable panel.

examples/data-table-expandable.tsx
"use client";
import {
DataTable,
type DataTableColumn,
} from "@/components/wensity/data-table";
type Invoice = {
id: string;
customer: string;
plan: string;
status: string;
detail: string;
};
const columns: DataTableColumn<Invoice>[] = [
{ id: "customer", header: "Customer", accessorKey: "customer" },
{ id: "plan", header: "Plan", accessorKey: "plan" },
{ id: "status", header: "Status", accessorKey: "status" },
];
export function ExpandableDataTable({ data }: { data: Invoice[] }) {
return (
<DataTable
columns={columns}
data={data}
expandable={{
renderExpanded: (row) => (
<div className="text-xs text-muted-foreground">
<p><strong>ID:</strong> {row.id}</p>
<p>{row.detail}</p>
</div>
),
}}
/>
);
}

Props

PropTypeDefaultDescription
columnsDataTableColumn<TData>[]-Column definitions. Required.
dataTData[]-Row data. Required.
getRowId(row: TData) => string-Unique row key. Defaults to row.id as a string.
sortablebooleanfalseEnables sorting on any column marked sortable.
filterableboolean | DataTableFilterConfigfalseEnables search. Pass a config object to customise it.
selectableboolean | DataTableSelectableConfig<TData>falseEnables checkbox row selection. Pass a config object for controlled mode.
paginatedboolean | DataTablePaginationConfigfalseEnables pagination. Defaults to 10 rows per page.
expandableboolean | DataTableExpandableConfig<TData>falseEnables expandable rows. Pass a config with renderExpanded.
density"compact" | "comfortable" | "spacious""comfortable"Row height and cell padding.
stickyHeaderbooleanfalsePins the header row while the body scrolls.
emptyStateReact.ReactNode-Shown when no rows match the current filters.
captionstring-Caption rendered below the table.