Shadcn Table with Bulk Actions Bar
Tick a few rows and a toolbar floats up to assign an owner, change the status or delete them, with undo for each. Tick the whole page and the selection can grow to every row the filter matches, not just the ones loaded. Shown as a CRM lead list.
$ npx shadcn add https://www.shad-table.dev/r/bulk-actions-table.json| Lead | Status | Owner | Source | Created | |
|---|---|---|---|---|---|
Harper Silva Bluth Company | Contacted | Jonas Weber | Website | Nov 28 | |
Zoe Brown Hooli | Contacted | Jonas Weber | Outbound | Nov 28 | |
Charlotte Lewis Wonka | New | Tom Okafor | Website | Nov 28 | |
Evelyn Thompson Vandelay | New | Unassigned | Website | Nov 28 | |
Charlotte Thompson Umbrella | Qualified | Tom Okafor | Outbound | Nov 28 | |
Harper Thompson Globex | New | Maya Chen | Event | Nov 28 | |
Ethan Martin Sterling Cooper | Contacted | Maya Chen | Outbound | Nov 28 | |
Lucas Chen Bluth Company | New | Tom Okafor | Event | Nov 28 | |
Nina Wilson Dunder Mifflin | New | Unassigned | Website | Nov 28 | |
Amelia Brown Wonka | New | Unassigned | Outbound | Nov 28 |
1–10 of 1,240
How it works
1.A selection that can outgrow the page
Only one page of leads is loaded, like a server-paginated list, so "all 1,240" cannot be a list of ids. The selection is either the ids you ticked, or everything the filter matches minus the rows you unticked afterwards. The count, the checkboxes and the actions all read from that one value.
export type Selection =| { mode: 'ids'; ids: ReadonlySet<string> }| { mode: 'all'; except: ReadonlySet<string> }
2.TanStack still drives the checkboxes
The table gets a rowSelection built for the rows on screen, so the header checkbox, its dash state and toggleAllPageRowsSelected work as usual. Whatever TanStack returns is mapped back onto the selection, which is how unticking a row in "all matching" mode adds it to the exceptions.
function onRowSelectionChange(updater) {const next = typeof updater === 'function' ? updater(rowSelection) : updatersetSelection((current) => {const updated = page.rows.reduce((acc, lead) => setSelected(acc, lead.id, !!next[lead.id]),current,)return selectedCount(updated, page.total) === 0 ? noSelection : updated})}
3.Changing the filter clears the selection
"All matching" only means something for the filter it was made under, and ids picked under another filter could be acted on without being seen. Searching or switching status starts a fresh selection, as Gmail does.
function changeQuery(next: Partial<Query>) {setQuery((current) => ({ ...current, ...next }))setSelection(noSelection)setPageIndex(0)}
4.Undo instead of a confirm dialog
Assign and status changes apply at once and remember the values they replaced. Delete only hides the rows; the real delete runs when the six-second undo window closes, or when the next action starts. Undo takes focus because the button you pressed is gone. The timer pauses while the pointer is over the bar or keyboard focus is in it, but not for that automatic focus, or a mouse user would never see the notice go.
setHidden((current) => new Set([...current, ...ids]))runAction(`Deleted ${plural(ids.size, 'lead')}`,() => setHidden(without),() => {setLeads((current) => current.filter((lead) => !ids.has(lead.id)))setHidden(without)},)
5.A bar that follows you down the page
The bar is fixed to the bottom of the viewport, not placed after the table, so it stays in reach wherever you scroll, even on a long list. Its full-width wrapper ignores the pointer, so only the bar itself blocks clicks on the rows behind it. It only appears when something is selected, and Escape clears the selection.
<div className="pointer-events-none fixed inset-x-0 bottom-6 z-50 flex justify-center"><div role="toolbar" aria-label="Bulk actions" className="pointer-events-auto ...">