Skip to Content
Skip to content

Data Table

Data table recipe: TanStack Table v9 wired to the neu table, with sorting, filtering, column visibility, row selection and pagination composed from existing neu components.

Status
Amount
success
ken99@example.com
$316.00
success
abe45@example.com
$242.00
processing
monserrat44@example.com
$837.00
success
silas22@example.com
$874.00
failed
carmella@example.com
$721.00
pending
liana8@example.com
$529.00
success
otto31@example.com
$190.00
processing
priya12@example.com
$645.00
0 of 12 row(s) selected.

Installation

bunx --bun shadcn@latest add https://neu.beyondtheinnovation.com/r/neu-data-table-demo.json

This installs the full recipe file plus the neu table, button, checkbox, dropdown menu and input it composes, and adds @tanstack/react-table (v9).

Usage

The recipe is one file: column definitions plus a table component. TanStack Table v9 registers behavior as features; the neu components render it. The core wiring:

"use client"

import {
  createColumnHelper,
  createSortedRowModel,
  rowSortingFeature,
  sortFn_alphanumeric,
  tableFeatures,
  useTable,
} from "@tanstack/react-table"

import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/ui/neu/table"

type Payment = {
  id: string
  amount: number
  status: "pending" | "processing" | "success" | "failed"
  email: string
}

const features = tableFeatures({
  rowSortingFeature,
  sortedRowModel: createSortedRowModel(),
  sortFns: { alphanumeric: sortFn_alphanumeric },
})

const helper = createColumnHelper<typeof features, Payment>()

const columns = helper.columns([
  helper.accessor("status", { header: "Status" }),
  helper.accessor("email", { header: "Email" }),
])

export function DataTable({ data }: { data: Payment[] }) {
  const table = useTable({ features, data, columns })

  return (
    <Table>
      <TableHeader>
        {table.getHeaderGroups().map((headerGroup) => (
          <TableRow key={headerGroup.id}>
            {headerGroup.headers.map((header) => (
              <TableHead key={header.id}>
                {header.isPlaceholder ? null : (
                  <table.FlexRender header={header} />
                )}
              </TableHead>
            ))}
          </TableRow>
        ))}
      </TableHeader>
      <TableBody>
        {table.getRowModel().rows.map((row) => (
          <TableRow key={row.id}>
            {row.getVisibleCells().map((cell) => (
              <TableCell key={cell.id}>
                <table.FlexRender cell={cell} />
              </TableCell>
            ))}
          </TableRow>
        ))}
      </TableBody>
    </Table>
  )
}

The installed neu-data-table-demo.tsx extends this with email filtering through the neu input, a column visibility dropdown, checkbox row selection and Previous/Next pagination. Each behavior is a feature registered in tableFeatures plus its row-model slot; delete the ones you do not need and their UI.

On this page