Search docs

Jump to any table example

Shadcn Realtime Collaborative Table

A table several people edit at once. You see their cursors and the cells they have selected, rows light up in their color as their edits arrive, and a cell someone is typing in stays locked until they finish.

$ npx shadcn add https://www.shad-table.dev/r/realtime-collab-table.json
  • You
  • Maya
  • Theo
  • Ines
Live
TaskOwnerStatusPriorityEstimateLast edit
Ship billing settings pageT-101
Maya Chen
In progress
(Maya Chen is here)
High
5 pts
Maya · 42s ago
Migrate auth to passkeysT-102
Theo Laurent
In review
Urgent
(Theo Laurent is here)
8 pts
Theo · 3m ago
Write release notesT-103
Ines Okafor
To do
Medium
2 pts
Ines · 10m ago
Fix CSV export encodingT-104
Sam Rivera
Blocked
High
3 pts
Theo · 1m ago
Onboarding checklist copyT-105
Jo Park
Done
Low
1 pts
You · 1h ago
Rate-limit public APIT-106
Theo Laurent
To do
High
5 pts
Maya · 20m ago
Dashboard empty statesT-107
(Ines Okafor is here)
Ines Okafor
In progress
Medium
3 pts
Ines · 20s ago

Click a cell, or use the arrow keys. Enter or double-click edits it.

How it works

1.Presence is a cell, a pointer and a typing flag

Each person in the room reports the cell they have selected, where their pointer sits inside it, and whether they are typing there. The demo plays them from a seeded script; in your app they come from Liveblocks, Yjs awareness or your own websocket.

src/components/realtime-collab/presence.ts
interface Peer {
id: string
cell: { rowId: string; field: Field }
pointer: { x: number; y: number }
typing: number
}

2.Selections are rings in each person’s color

A cell someone else has selected gets an inset ring in their color and a name tag on its top edge. Your own selection is an outline that sits inside their ring, so a shared cell shows both. The tag reads "is editing…" while they type, and screen readers get the same text.

src/components/realtime-collab/data-table.tsx
style={{ boxShadow: `inset 0 0 0 ${mine ? 4 : 2}px ${first.color}` }}
className={cn(mine && 'outline-2 -outline-offset-2 outline-foreground')}

3.Cursors are placed relative to cells, not pixels

A pointer is sent as a position inside a cell, then measured against that cell here. It lands on the right cell at any width or horizontal scroll, and glides between cells with a 300ms transform that is turned off for reduced motion.

src/components/realtime-collab/peer-cursors.tsx
const box = cell.getBoundingClientRect()
next[peer.id] = {
x: box.left - frame.left + box.width * peer.pointer.x,
y: box.top - frame.top + box.height * peer.pointer.y,
}

4.Rows light up in the editor’s color

When someone else changes a row, it takes a soft wash of their color for about a second and fades out, and the Last edit column says who and when. The color is never the only signal. getRowId keeps your selection on the same task while edits stream in.

src/components/realtime-collab/data-table.tsx
style={fresh ? {
backgroundColor: `color-mix(in oklch, ${editor.color} 12%, transparent)`,
} : undefined}

5.A cell being edited is locked

Nobody starts typing in the cell you are editing, and you cannot open a cell while someone else types in it; you get a message instead. Updates can be paused, since content that changes on its own should never be impossible to stop.

src/components/realtime-collab/presence.ts
export function edit(room: Room, cell: CellRef, value: Task[Field]) {
if (lockedBy(room, cell)) return room
// …
}