Config-driven reusable data table with sort, filter, and paging
A warehouse team has outgrown one-off tables: every page (inventory, suppliers, shipments) needs the same sorting, filtering and pagination. Build a reusable data table driven entirely by a column config, then use it to render the inventory grid.
The starter code includes 17 inventory items, a page size of 5, and the column config:
const INVENTORY = [
{ sku: 'SKU-101', name: 'Wireless Earbuds', category: 'Audio', stock: 42, price: 59.99 },
{ sku: 'SKU-102', name: 'Type-C Cable 1m', category: 'Cables', stock: 310, price: 9.5 },
// ... 15 more, up to SKU-117
];
const COLUMNS = [
{ key: 'sku', label: 'SKU', sortable: true },
{ key: 'name', label: 'Product', sortable: true, filter: 'text' },
{ key: 'category', label: 'Category', filter: 'select' },
{ key: 'stock', label: 'Stock', sortable: true, numeric: true },
{ key: 'price', label: 'Price', sortable: true, numeric: true, format: (value) => `$${Number(value).toFixed(2)}` },
];
Implement DataTable({ columns, rows, rowKey, pageSize }) (React) or createDataTable(container, { columns, rows, rowKey, pageSize }) (vanilla). The starter already calls it with the inventory data. Nothing inside the table may refer to inventory fields: everything comes from columns.
key: the row field shown in the column. label: the header text.sortable: the header is a button that sorts by this column.filter: 'text' renders a text input, 'select' renders a dropdown. Label both Filter {label} (for example Filter Product).numeric: right-align the column (styling only). format: turns a value into display text. Without it, show the raw value.9.5 comes before 119) and strings alphabetically. You may append an arrow (▲ or ▼) to the header text.Page X of Y, and Showing A–B of N, where N counts the rows that match the filters. Disable Previous on the first page and Next on the last page.Showing 0–0 of 0 and Page 1 of 1.Default: SKU-101 … SKU-105 Page 1 of 4 Showing 1–5 of 17
Next × 3 (last page): SKU-116, SKU-117 Page 4 of 4 Showing 16–17 of 17
Click Price: SKU-114 ($8.25), SKU-102 ($9.50), SKU-115, SKU-106, SKU-110
Click Price again: SKU-113 ($229.00), SKU-117, SKU-105, SKU-103, SKU-111
Click Price again: SKU-101 … SKU-105 (original order)
Filter Product = "CABLE": SKU-102, SKU-106, SKU-110, SKU-114 Showing 1–4 of 4
Filter Category = Storage: SKU-103, SKU-107, SKU-111, SKU-115
+ Filter Product = "usb": SKU-115
rows when sorting: the third click must be able to restore the original order.The tests click your buttons, type in your inputs, change the dropdown, and read the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
<select> labelled Filter Category (a <label>, aria-label, placeholder or name), whose options’ visible text is All and the category names.disabled attribute (or don’t render it).Page X of Y, Showing A–B of N (a hyphen works instead of the en dash) and No matching items is correct after every action.Capitalization and extra spacing don’t matter.