Search docs

Jump to any table example

Discord—

Shadcn Table with Draft Rows

Type several new rows straight into the table, see what needs fixing as you go, then save or discard them together. Built here as an expense report; the same works for order items or stock counts.

$ npx shadcn add https://www.shad-table.dev/r/draft-rows-table.json

Expense report November 2026

4 saved · $726.90

DateDescriptionCategoryAmountActions
Nov 3Train to LyonTravel$86.40
Nov 3Hotel Bellecour, 2 nightsLodging$312.00
Nov 4Client dinnerMeals$148.50
Nov 10Figma, annual seatSoftware$180.00
Duplicate?
Enter in a description or amount moves down a row, and adds one at the end.

3 new rows$191.30· 1 needs fixing1 possible duplicate

How it works

1.Saved rows and drafts in one table

The table gets one list: saved expenses, then the drafts, each tagged with its kind. Every column renders plain text for a saved row and an input for a draft, so new rows sit right under the ones they join, with the same columns. Drafts keep the raw text from their inputs until the batch is saved.

src/components/draft-rows/columns.tsx
export type Row =
| { kind: 'saved'; id: string; expense: Expense }
| { kind: 'draft'; id: string; draft: Draft; number: number }

2.Errors show when they are useful

Rows are validated on every keystroke, but a field only shows its error after you leave it, so a half-typed row is not covered in red. Pressing Save with mistakes shows every error and moves focus to the first one. Blank rows are skipped, so an empty row at the end never blocks saving.

src/components/draft-rows/index.tsx
const visible = (field) =>
(attempted && !isBlank(draft)) || touched.has(`${id}:${field}`)

3.Typing several rows from the keyboard

The date is a shadcn date picker limited to the report period, and the category a shadcn Select; both count as touched when they close. In the description and amount, Enter moves to the same field one row down and adds a row at the end, starting on the date of the row above. Removing a row moves focus to its neighbour, so focus is never lost.

src/components/draft-rows/index.tsx
if (i === drafts.length - 1) addRow(field)
else focusTarget.current = { id: drafts[i + 1].id, field }

4.Possible duplicates warn, but do not block

A draft with the same date, amount and description as a saved expense, or as another draft, gets a Duplicate? note. It is a warning rather than an error, because two identical taxi rides in a day can be real.

src/components/draft-rows/drafts.ts
export function duplicates(drafts: Draft[], existing: Expense[]): Set<string>

5.One save for the batch

Save sends every filled row together and turns them into saved rows, which flash green for a moment. Discard asks once more before throwing away rows with something typed in.

src/components/draft-rows/index.tsx
const added = summary.filled.map((d) => toExpense(d, newId()))
setSaved((s) => [...s, ...added].sort(byDate))
setDrafts([])