Reusable table with Shift+click multi-column sort and paging
A payments dashboard shows a ledger of payouts to merchants. Finance analysts want to sort it the way they sort a spreadsheet: click a header to sort by that column, and Shift+click more headers to break ties (for example, “by status, then by amount”). Build a reusable data table with multi-column sorting and numbered pagination, then use it to render the payouts ledger.
The starter code includes 14 payouts, a page size of 4, and the column config:
const PAYOUTS = [
{ id: 'PO-201', recipient: 'Juniper Labs', status: 'Paid', amount: 1200, date: '2026-03-02' },
{ id: 'PO-202', recipient: 'Kestrel Foods', status: 'Failed', amount: 85.5, date: '2026-03-02' },
// ... 12 more, up to PO-214
];
const COLUMNS = [
{ key: 'id', label: 'Payout' },
{ key: 'recipient', label: 'Recipient', sortable: true },
{ key: 'status', label: 'Status', sortable: true, compare: compareStatus },
{ key: 'amount', label: 'Amount', sortable: true, render: formatAmount },
{ key: 'date', label: 'Date', sortable: true, render: formatDate },
];
Implement DataTable({ columns, rows, rowKey, pageSize }) (React) or createDataTable(container, { columns, rows, rowKey, pageSize }) (vanilla). The starter already calls it with the payouts. Nothing inside the table may refer to payout fields: everything comes from its arguments.
key: the row field shown in the column. label: the header text.sortable: when true, the header is a button. Otherwise it is plain text.compare(a, b): optional. Compares two cell values like an Array.prototype.sort comparator. Without it, compare numbers numerically and everything else with localeCompare. Here, compareStatus orders statuses by urgency: Failed, Pending, In transit, Paid.render(value): optional. Turns a cell value into display text (1200 → $1,200.00, '2026-03-02' → Mar 2, 2026). Without it, show the raw value.The table keeps an ordered list of sort keys, each a column and a direction. Rows are compared by the first key, then by the second key when the first is a tie, and so on. Rows that tie on every key keep their original order, in both directions.
Sorted by Status (ascending), Amount (descending), or Not sorted when there are none.aria-current="page". Disable Previous on the first page and Next on the last.Default: PO-201, PO-202, PO-203, PO-204 Not sorted
Click Amount: PO-210, PO-202, PO-204, PO-208 Sorted by Amount (ascending)
Click Amount again: PO-205, PO-209, PO-201, PO-207 Sorted by Amount (descending)
Click Amount again: PO-201, PO-202, PO-203, PO-204 Not sorted
Click Status: PO-202, PO-207, PO-214, PO-203 (Failed first, then Pending)
Shift+click Amount: PO-202, PO-214, PO-207, PO-213 Sorted by Status (ascending), Amount (ascending)
Shift+click Amount again: PO-207, PO-214, PO-202, PO-209 Sorted by Status (ascending), Amount (descending)
Shift+click Amount again: PO-202, PO-207, PO-214, PO-203 Sorted by Status (ascending)
Click Recipient: PO-203, PO-207, PO-212, PO-204 Sorted by Recipient (ascending)
Click 3: PO-209 … PO-212
Click Next (page 4): PO-213, PO-214 Next disabled
rows: removing the last sort key must restore the original order.rows array still shows one page.The tests click your buttons and read the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. Shift+click is a click event with shiftKey: true, so read event.shiftKey in your click handler. They check that:
PO-2xx) of the current page only, in order, with the rendered amount and date.Sorted by … or Not sorted) is correct after every click.aria-current="page". When Previous or Next must not be used, give it the disabled attribute (or don’t render it).Capitalization and extra spacing don’t matter.