Search docs

Jump to any table example

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
LeadStatusOwnerSourceCreated
Harper Silva
Bluth Company
ContactedJonas WeberWebsiteNov 28
Zoe Brown
Hooli
ContactedJonas WeberOutboundNov 28
Charlotte Lewis
Wonka
NewTom OkaforWebsiteNov 28
Evelyn Thompson
Vandelay
NewUnassignedWebsiteNov 28
Charlotte Thompson
Umbrella
QualifiedTom OkaforOutboundNov 28
Harper Thompson
Globex
NewMaya ChenEventNov 28
Ethan Martin
Sterling Cooper
ContactedMaya ChenOutboundNov 28
Lucas Chen
Bluth Company
NewTom OkaforEventNov 28
Nina Wilson
Dunder Mifflin
NewUnassignedWebsiteNov 28
Amelia Brown
Wonka
NewUnassignedOutboundNov 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.

src/components/bulk-actions/selection.ts
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.

src/components/bulk-actions/data-table.tsx
function onRowSelectionChange(updater) {
const next = typeof updater === 'function' ? updater(rowSelection) : updater
setSelection((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.

src/components/bulk-actions/data-table.tsx
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.

src/components/bulk-actions/data-table.tsx
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.

src/components/bulk-actions/bulk-actions-bar.tsx
<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 ...">