Naalya Handbook
Design system

Data tables

How each feature assembles its own table, filters, and pagination from shared parts, and why there is no single DataTable.

Each feature assembles its own table from shared parts. There is no single <DataTable> component, and that is deliberate. Every list in the Education Hub (inquiries, students, staff, applications) has its own columns, filters, and pagination, and one component bent into all those shapes by props would be hard to read.

Shared parts do the repetitive work: the chrome, the row models, the loading skeleton. Feature-owned parts describe what is unique: which columns, which filters, which cells. Once you have read one feature's folder, you can read them all.

Four files per table

Four files make up every table, in src/components/data-tables/<feature>/. The examples on this page use the inquiry table:

  • datatable.tsx: the orchestrator. Holds query params, fetches, builds the table, and lays out the filter and the shell.
  • columns.tsx: the column definitions. What each column is and how its cell renders.
  • filter.tsx: the toolbar above the table. Search, faceted filters, and column visibility.
  • cells/: custom cell renderers, such as actions.cell.tsx and status.cell.tsx.

Two shared helpers tie them together: useDataTable, a thin wrapper over useReactTable, and DataTableShell, the table chrome every feature renders the same way. Neither knows anything about inquiries.

Orchestrator owns the params and the query

datatable.tsx is small on purpose. It owns the query params as local state, hands them to the feature's query hook, feeds the result into useDataTable, and renders the filter on top of the shell.

src/components/data-tables/inquiry/datatable.tsx
const [params, setParams] = useState<ListEnquiriesQueryParams>({ limit: 100 })
const { inquiries, loadingInquiries, fetchingInquiries } = useInquiries(params)

const table = useDataTable({
  data: inquiries?.data ?? [],
  columns: inquiryColumns,
  defaultColumnVisibility: { id: false },
})

Generated types check the params: params is a ListEnquiriesQueryParams, the same contract the API speaks, so search, status, and date filters are type-checked against the real endpoint. The filter receives params and setParams; when a user picks a status, it patches that state and the query refetches.

Memoize the fallback before useDataTable

useDataTable takes a data array. If you pass inquiries?.data ?? [], that ?? [] creates a brand-new array on every render when data is undefined, and a new array reference makes TanStack Table treat the data as changed, which can spin into a render loop. When the fallback is anything more than the simplest case, hoist it into a useMemo so the empty array stays referentially stable.

Table state comes from useDataTable

useDataTable saves every feature from repeating the useReactTable boilerplate. It wires up four pieces of table state (sorting, column filters, row selection, column visibility) and registers the standard row models.

src/components/data-tables/use-data-table.ts
const table = useReactTable({
  data,
  columns,
  getCoreRowModel: getCoreRowModel(),
  getSortedRowModel: getSortedRowModel(),
  getPaginationRowModel: getPaginationRowModel(),
  getFilteredRowModel: getFilteredRowModel(),
  // ...state + onChange handlers
})

Selected rows, filter values, and visible columns all come off this one table instance. The orchestrator passes it to both the filter and the shell.

Columns: select first, actions last

A select column always comes first and an actions column always comes last, with the visible columns in between. columns.tsx describes them with createColumnHelper, typed to the feature's DTO so every accessor is checked against a real field.

src/components/data-tables/inquiry/columns.tsx
const columnHelper = createColumnHelper<EnquiryDto>()

const inquiryColumns = [
  createSelectColumn<EnquiryDto>(),           // first: the checkbox
  columnHelper.accessor('name', { header: 'Name', cell: /* ... */ }),
  columnHelper.accessor('status', { header: 'Status', filterFn: 'equals', cell: /* ... */ }),
  // ...more accessors
  columnHelper.display({ id: 'actions', enableHiding: false, cell: /* ... */ }), // last
]

Three more conventions:

  • Headers are plain strings, such as header: 'Status', not components. The file stays readable.
  • Rich cells delegate to a renderer in cells/. The status column renders <StatusCell row={info.row.original} />.
  • Shared context comes from table.options.meta, such as an open-panel callback or the current user, not from props threaded through the shell.

meta beats prop drilling

useDataTable accepts a meta object that lands on table.options.meta. Anything a cell needs that is not on the row (callbacks, the active campus, permission flags) goes there. The shell flex-renders cells without knowing their props, so meta is the only clean channel into a cell. Reach for it instead of widening DataTableShell's prop list.

filter.tsx is the toolbar above the table, and it holds most of what makes a feature's table different. The inquiry filter has a search box, faceted dropdowns for staff, priority and status, a date-range picker, and a column-visibility popover. The faceted filters drive TanStack's column filters via table.getColumn('status')?.setFilterValue(...); the search box drives the server params.

Search is debounced so typing does not fire a request on every keystroke. It uses debounce from @tanstack/pacer: the input updates at once, but the params (and so the query) update only when typing settles, about 800ms later.

src/components/data-tables/inquiry/filter.tsx
const [searchValue, setSearchValue] = useState(params?.search || '')

const debouncedSearch = useMemo(
  () =>
    debounce((search: string) => setParams((p) => ({ ...p, search })), { wait: 800 }),
  [setParams],
)

// <Input value={searchValue} onChange={(e) => {
//   setSearchValue(e.target.value)      // instant, local
//   debouncedSearch(e.target.value)     // settles after 800ms, then refetches
// }} />

Filter state lives in local useState, not the URL. The filter stays self-contained and refetches stay quick. The trade-off: a filtered view cannot be shared by link and is lost on refresh. Shareable filters would be a deliberate change, not the default.

DataTableShell is the chrome every table renders the same way, so no feature rebuilds the header rows, the loading state, or the empty state. Give it the table, the columns, and the loading flags. Top to bottom, it renders:

  • Total-count badge, from the paginated response (totalCount and a recordLabel such as "inquiries").
  • Loading skeleton, while isLoading is true.
  • Table or empty state: header and body flex-rendered and dimmed during a background refetch, or an empty state when there are no rows.
  • Pagination footer.
src/components/data-tables/inquiry/datatable.tsx
<DataTableShell
  table={table}
  columns={inquiryColumns}
  isLoading={loadingInquiries}
  isFetching={fetchingInquiries}
  totalCount={inquiries?.totalCount ?? 0}
  recordLabel="inquiries"
  emptyTitle="No Inquiries Found"
/>

isFetching fades the table to half opacity during a background refetch, so a filter change shows progress without removing the old rows.

Pagination: client or server cursor

Pick a pagination system before you build a new table. There are two, and they do not mix. It is the one real decision a new table needs.

Client pagination is the simple path. Ask the API for a big page, limit: 100, then let TanStack's getPaginationRowModel slice it into pages in the browser. The shell's built-in DataTablePagination footer drives it. Inquiry works this way. It is fine when a tenant will never have thousands of rows.

Server cursor pagination is the scalable path. The table holds one page at a time and asks the server for the next via a cursor. State comes from the shared useCursorParams, and you render CursorPaginationFooter instead of the default footer (passing hidePagination to the shell).

src/components/data-tables/platform/_shared/use-cursor-params.ts
const { params, onSearch, onNext, onPrev, canPrev } = useCursorParams(20)
// onNext pushes the current cursor onto a stack so onPrev can rewind

onNext advances afterId and remembers the previous cursor, so Previous can step back. The platform student, staff, guardian, and guest tables use this system.

Known debt: read before copying a table

  • Sorting UI is unwired. getSortedRowModel is registered but no header toggles it, so columns do not sort yet.
  • Most staff tables over-fetch with limit: 100 and paginate in the browser. Fine for small tenants; it will not scale.
  • Prefer the cursor system for any list that can grow large. Retrofitting it later means reworking the orchestrator and the filter together.

Where to go next

On this page