Tables purposefully designed for dynamic, application data with features like sorting, filtering, and pagination. Powered by TanStack Table.
import {
DataTable,
createColumnHelper,
getCoreRowModel,
getFilteredRowModel,
getPaginationRowModel,
getSortedRowModel,
useReactTable,
} from "@ngrok/mantle/data-table";
type Payment = {
id: string;
amount: number;
status: "pending" | "processing" | "success" | "failed";
email: string;
};
const columnHelper = createColumnHelper<Payment>();
const columns = [
columnHelper.accessor("id", {
id: "id",
header: (props) => (
<DataTable.Header>
<DataTable.HeaderSortButton column={props.column} sortingMode="alphanumeric">
ID
</DataTable.HeaderSortButton>
</DataTable.Header>
),
cell: (props) => <DataTable.Cell key={props.cell.id}>{props.getValue()}</DataTable.Cell>,
}),
// ... more columns
];
function PaymentsExample() {
const data = useMemo(() => examplePayments, []);
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
initialState: {
sorting: [{ id: "email", desc: false }],
pagination: { pageSize: 100 },
},
});
const rows = table.getRowModel().rows;
return (
<DataTable.Root table={table}>
<DataTable.Head />
<DataTable.Body>
{rows.length > 0 ? (
rows.map((row) => (
<DataTable.Row
className="cursor-pointer"
key={row.id}
onClick={() => {
window.alert(`Clicked payment row: ${row.original.id}`);
}}
row={row}
/>
))
) : (
<DataTable.EmptyRow>
<p className="flex items-center justify-center min-h-20">No results.</p>
</DataTable.EmptyRow>
)}
</DataTable.Body>
</DataTable.Root>
);
}The DataTable components are built on top of TanStack Table. All TanStack Table utilities (createColumnHelper, getCoreRowModel, getSortedRowModel, etc.) are re-exported from @ngrok/mantle/data-table.
The root container for the data table. Wraps all other DataTable sub-components and provides the table context.
All additional props from Table.Root.
Automatically renders column headers from the table instance. Does not accept children.
All props from the HTML thead element.
The table body container for rows of data.
All props from the HTML tbody element.
Renders a single data row using the column definitions from the table instance.
All additional props from the HTML tr element.
An empty state row that spans all columns. Use when there is no data to display.
All props from the HTML tr element.
A header cell component optimized for data table header actions.
All props from Table.Header.
A sortable button toggle for column headers. Clicking cycles through sort directions.
All additional props from Button.
A table cell component for rendering individual data cells.
All props from Table.Cell.
A sticky action cell positioned at the end of each row for action buttons.
All props from Table.Cell.