GooseUI

Components

Data Table

New

A data table on a real <table>, rendered on the server: cells, badges and formatted numbers never reach the client bundle. A small client controller adds sorting, search and pagination by moving and hiding the existing rows. Row selection is native checkboxes: the highlight is pure CSS through :has(:checked), and inside a form the selected ids are submitted like any other field. The header and the first column stay pinned while you scroll.

Browser Support

Limited availability
5 features
Details
:has()

Highlights selected rows and shows the bulk actions. Without it selection still works, rows are just not tinted.

Your browser:
Scroll-driven animations

Fades in the shadow of the pinned column when you scroll sideways. Without it a static border marks the edge.

Your browser:
scripting media query

Hides the pager, search and select-all when JavaScript is off, and shows every row instead of the first page.

Your browser:
color-mix()

Mixes the zebra, hover and selection tints.

Your browser:
Customizable <select>

Styles the open list of the rows-per-page select; other browsers keep the native list.

Your browser:

Preview

Sort by any header, search by client or status, select a few rows: the toolbar appears and counts them.

Invoices
INV-2041
Northwind Traders
ap@northwind.com
PaidDec 20$240
INV-2040
Orbit Analytics
ap@orbitanalytics.ai
DraftDec 16$8,159
INV-2039
Bramble Coffee Roasters
hello@bramblecoffee.co
OverdueDec 13$7,079
INV-2038
Lumen Dental Group
billing@lumendental.com
PaidDec 9$5,997
INV-2037
Marigold Events
team@marigoldevents.com
PendingDec 6$4,917
INV-2036
Atlas Physio
admin@atlasphysio.com
PaidDec 3$3,837
INV-2035
Harbor & Pine Architects
finance@harborpine.com
PendingNov 29$2,755
INV-2034
Stonebridge Schools
procurement@stonebridge.edu
PaidNov 26$1,675
INV-2033
Greyfield Legal LLP
accounts@greyfield.law
DraftNov 22$593
INV-2032
Kestrel Logistics
invoices@kestrel.io
OverdueNov 19$8,511
INV-2031
Northwind Traders
ap@northwind.com
PaidNov 16$7,431
INV-2030
Orbit Analytics
ap@orbitanalytics.ai
PendingNov 12$6,349
INV-2029
Bramble Coffee Roasters
hello@bramblecoffee.co
PaidNov 9$5,269
INV-2028
Lumen Dental Group
billing@lumendental.com
PendingNov 5$4,189
INV-2027
Marigold Events
team@marigoldevents.com
PaidNov 2$3,107
INV-2026
Atlas Physio
admin@atlasphysio.com
DraftOct 30$2,027
INV-2025
Harbor & Pine Architects
finance@harborpine.com
OverdueOct 26$945
INV-2024
Stonebridge Schools
procurement@stonebridge.edu
PaidOct 23$8,863
INV-2023
Greyfield Legal LLP
accounts@greyfield.law
PendingOct 19$7,783
INV-2022
Kestrel Logistics
invoices@kestrel.io
PaidOct 16$6,701
INV-2021
Northwind Traders
ap@northwind.com
PendingOct 13$5,621
INV-2020
Orbit Analytics
ap@orbitanalytics.ai
PaidOct 9$4,541
INV-2019
Bramble Coffee Roasters
hello@bramblecoffee.co
DraftOct 6$3,459
INV-2018
Lumen Dental Group
billing@lumendental.com
OverdueOct 2$2,379
INV-2017
Marigold Events
team@marigoldevents.com
PaidSep 29$1,297
INV-2016
Atlas Physio
admin@atlasphysio.com
PendingSep 26$9,215
INV-2015
Harbor & Pine Architects
finance@harborpine.com
PaidSep 22$8,135
INV-2014
Stonebridge Schools
procurement@stonebridge.edu
PendingSep 19$7,055
INV-2013
Greyfield Legal LLP
accounts@greyfield.law
PaidSep 15$5,973
INV-2012
Kestrel Logistics
invoices@kestrel.io
DraftSep 12$4,893
INV-2011
Northwind Traders
ap@northwind.com
OverdueSep 9$3,811
INV-2010
Orbit Analytics
ap@orbitanalytics.ai
PaidSep 5$2,729
INV-2009
Bramble Coffee Roasters
hello@bramblecoffee.co
PendingSep 2$1,649
INV-2008
Lumen Dental Group
billing@lumendental.com
PaidAug 29$567
INV-2007
Marigold Events
team@marigoldevents.com
PendingAug 26$8,487
INV-2006
Atlas Physio
admin@atlasphysio.com
PaidAug 23$7,407
INV-2005
Harbor & Pine Architects
finance@harborpine.com
DraftAug 19$6,325
1–8 of 37

Installation

npx shadcn@latest add @gooseui/data-table
pnpm dlx shadcn@latest add @gooseui/data-table
yarn dlx shadcn@latest add @gooseui/data-table
bunx --bun shadcn@latest add @gooseui/data-table

Usage

import { DataTable, type DataTableColumn } from "@/components/ui/data-table"

type Invoice = {
  number: string; client: string; amount: number; due: Date
  status: "paid" | "pending" | "overdue" | "draft"
}

const money = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" })

const year = new Date().getUTCFullYear()
const formatDay = (d: Date) =>
  new Intl.DateTimeFormat("en-US", {
    month: "short", day: "numeric",
    year: d.getUTCFullYear() === year ? undefined : "numeric",
  }).format(d)

const tones = { paid: "success", pending: "warning", overdue: "danger", draft: "muted" } as const

const columns: DataTableColumn<Invoice>[] = [
  { id: "number", header: "Invoice", accessor: (r) => r.number, sortable: true,
    numeric: true, align: "left" },
  { id: "client", header: "Client", accessor: (r) => r.client, sortable: true },
  { id: "status", header: "Status", accessor: (r) => r.status, sortable: true,
    // Quiet status: a coloured dot plus plain text, red only for the one that needs action
    cell: (r) => <Badge variant="status" dot tone={tones[r.status]}>{r.status}</Badge> },
  { id: "due", header: "Due date", accessor: (r) => r.due, sortable: true,
    numeric: true, align: "left",
    // "Nov 16" this year, "Nov 16, 2025" otherwise
    cell: (r) => formatDay(r.due) },
  { id: "amount", header: "Amount", accessor: (r) => r.amount, sortable: true,
    numeric: true, cell: (r) => money.format(r.amount) },
]

// A Server Component: columns with cell functions stay on the server
export default async function Invoices() {
  const invoices = await getInvoices()
  return (
    <DataTable
      caption="Invoices"
      columns={columns}
      data={invoices}
      getRowId={(r) => r.number}
      defaultSorting={{ columnId: "due", direction: "desc" }}
      searchable
      pageSize={10}
    />
  )
}

Examples

Selection in a form

Every row checkbox is <input name="selected" value={id}>. Put the table in a form and a Server Action receives the ids; the bulk buttons are ordinary submit buttons.

async function deleteInvoices(formData: FormData) {
  "use server"
  const ids = formData.getAll("selected") // ["INV-2041", "INV-2038"]
  await db.invoice.deleteMany({ where: { number: { in: ids } } })
  revalidatePath("/invoices")
}

<form action={deleteInvoices}>
  <DataTable
    selectable
    columns={columns}
    data={invoices}
    getRowId={(r) => r.number}
    toolbar={
      <div data-selection-only className="ml-auto flex items-center gap-2">
        <span><b data-selected-count>0</b> selected</span>
        <button type="submit">Delete</button>
        <button type="button" data-table-clear-selection>Clear</button>
      </div>
    }
  />
</form>

Selection callback and loading

Rendered from a client component, the table accepts onSelectionChange, onSortingChange and onPageChange. Here the selection sums the amounts, and the button toggles the skeleton rows.

Select rows to see the total

Recent invoices
INV-2041Northwind TradersNov 20$240.00
INV-2040Orbit AnalyticsNov 16$8,159.13
INV-2039Bramble Coffee RoastersNov 13$7,079.26
INV-2038Lumen Dental GroupNov 9$5,997.39
INV-2037Marigold EventsNov 6$4,916.52
INV-2036Atlas PhysioNov 3$3,836.65
INV-2035Harbor & Pine ArchitectsOct 30$2,754.78
INV-2034Stonebridge SchoolsOct 27$1,674.91
INV-2033Greyfield Legal LLPOct 23$593.04
INV-2032Kestrel LogisticsOct 20$8,511.17
INV-2031Northwind TradersOct 17$7,431.30
INV-2030Orbit AnalyticsOct 13$6,349.43
"use client"

const [selected, setSelected] = useState<string[]>([])
const total = invoices
  .filter((r) => selected.includes(r.number))
  .reduce((sum, r) => sum + r.amount, 0)

<DataTable
  selectable
  loading={loading}
  columns={columns}
  data={invoices}
  getRowId={(r) => r.number}
  onSelectionChange={setSelected}
/>

Wide table

Twelve columns, far wider than the container. The checkbox and invoice columns are pinned on the left, the actions column on the right (stickyLastColumn). A fade and a round arrow button appear on the side that still has hidden columns, and each disappears at its end. Scroll with the arrows, the scrollbar, Shift + wheel, a swipe, or ← and → when the table is focused.

Invoices
Actions
INV-2041
Northwind Traders
ap@northwind.com
PaidNov 20Dec 20$240$48USDCardBen CarterAnalytics
INV-2040
Orbit Analytics
ap@orbitanalytics.ai
DraftNov 16Dec 16$8,159$1,632USDBank transferAlice MooreWebsite redesign
INV-2039
Bramble Coffee Roasters
hello@bramblecoffee.co
OverdueNov 13Dec 13$7,079$1,416USDPayPalDan WellsMobile app
INV-2038
Lumen Dental Group
billing@lumendental.com
PaidNov 9Dec 9$5,997$1,199USDInvoiceChloe ReedBrand identity
INV-2037
Marigold Events
team@marigoldevents.com
PendingNov 6Dec 6$4,917$983USDCardBen CarterAnalytics
INV-2036
Atlas Physio
admin@atlasphysio.com
PaidNov 3Dec 3$3,837$767USDBank transferAlice MooreWebsite redesign
INV-2035
Harbor & Pine Architects
finance@harborpine.com
PendingOct 30Nov 29$2,755$551USDPayPalDan WellsMobile app
INV-2034
Stonebridge Schools
procurement@stonebridge.edu
PaidOct 27Nov 26$1,675$335USDInvoiceChloe ReedBrand identity
INV-2033
Greyfield Legal LLP
accounts@greyfield.law
DraftOct 23Nov 22$593$119USDCardBen CarterAnalytics
INV-2032
Kestrel Logistics
invoices@kestrel.io
OverdueOct 20Nov 19$8,511$1,702USDBank transferAlice MooreWebsite redesign
INV-2031
Northwind Traders
ap@northwind.com
PaidOct 17Nov 16$7,431$1,486USDPayPalDan WellsMobile app
INV-2030
Orbit Analytics
ap@orbitanalytics.ai
PendingOct 13Nov 12$6,349$1,270USDInvoiceChloe ReedBrand identity
// 12 columns; the last one is the "Actions" column
<DataTable
  selectable
  stickyLastColumn
  columns={columns}
  data={invoices}
  getRowId={(r) => r.number}
  maxHeight="20rem"
/>

Empty and loading states

emptyState is shown when data is empty, noMatchState when the search finds nothing, loading renders skeleton rows.

Invoices
No disputed invoices. Nice.
Invoices
Loading rows…
<DataTable data={[]} emptyState="No disputed invoices. Nice." {...props} />
<DataTable loading loadingRows={3} {...props} />

Props

PropTypeDefaultDescription
columnsDataTableColumn<T>[]-Column definitions, see below
dataT[]-Rows
getRowId(row: T, index: number) => string-Stable id of a row; also the value of its checkbox
captionReactNode-Accessible name of the table
showCaptionbooleanfalseShow the caption under the table
defaultSorting{ columnId: string; direction: "asc" | "desc" } | nullnullOrder applied on the server
selectablebooleanfalseAdd a checkbox column
defaultSelectedIdsstring[]-Rows checked on first render
selectNamestring"selected"Form field name of the row checkboxes
searchablebooleanfalseSearch field that filters rows by their text
toolbarReactNode-Content next to the search field
pageSizenumber-Rows per page; turns pagination on
pageSizeOptionsnumber[]-Show a rows per page select
loadingbooleanfalseRender skeleton rows
loadingRowsnumber5Number of skeleton rows
emptyStateReactNode"No results."Content when data is empty
noMatchStateReactNode"No matching rows."Content when the search finds nothing
stickyFirstColumnbooleantruePin the first column and the checkboxes
stripedbooleanfalseZebra rows
stickyLastColumnbooleanfalsePin the last column (row actions) to the right edge
scrollButtonsbooleantrueRound arrow buttons on the edges of a table wider than its container; touch screens swipe instead
maxHeightnumber | string-Height of the scroll area, so the header sticks inside
labelsPartial<DataTableLabels>EnglishTexts for screen readers, the search and the pager
onSelectionChange / onSortingChange / onPageChangefunction-Client only: selection, sorting and page callbacks

DataTableColumn

FieldTypeDescription
idstringUnique column id
headerReactNodeHeader content
accessor(row: T) => unknownRaw value for the default cell and for sorting
cell(row: T, value: unknown) => ReactNodeCustom cell content
sortablebooleanMake the header a sort button
sortValue(row: T) => string | number | Date | nullValue to sort by instead of the accessor
align"left" | "center" | "right"Text alignment; numeric columns align right
numericbooleanTabular figures
widthnumber | stringColumn width

Toolbar hooks

AttributeDescription
data-selection-onlyShown only while at least one row is selected (CSS :has)
data-selected-countIts text becomes the number of selected rows
data-table-clear-selectionA click clears the selection

Features

  • Server first: rows and cells render on the server; the client part only moves and hides rows
  • Works without JavaScript: every row is shown, checkboxes are highlighted and submitted with a form
  • Real table semantics: caption, scope, aria-sort, aria-rowindex and aria-rowcount for screen readers
  • Keyboard: the scroll area is focusable, headers are buttons, checkboxes are native
  • Sticky header and first column: cells keep an opaque background so nothing shows through
  • Scroll arrows and edge fades: a wide table gets round arrow buttons and a fade on the sides that still hide columns; each goes away at its end, on touch screens swipe instead, and a table that fits shows none of it
  • Pinned actions column: stickyLastColumn keeps the last column on the right edge with a soft shadow while columns scroll under it
  • Reduced motion: no background transitions and no skeleton pulse