Skip to content
Niko Table

Core Components

The core pieces of every table: DataTableRoot, DataTable, header, body, and loading and empty states.

Core components are the base of every table. They set up the table, share context, and draw the structure.

DataTableRoot gives every child component the table context. Always wrap your table in it.

  • Creates the table: it calls useTable with the shared features object from lib/data-table-features.ts (TanStack Table v9).
  • Holds the state: it manages table state.
import { DataTableRoot } from "@/components/niko-table/core/data-table-root"
export function MyTable({ data }: { data: User[] }) {
return (
<DataTableRoot data={data} columns={columns}>
{/* child components */}
</DataTableRoot>
)
}
Name Type Description
children React.ReactNode Child components (required).
data TData[] The data array to display in the table.
columns DataTableColumnDef<TData>[] Column definitions array.
table DataTableInstance<TData> Pre-configured TanStack Table instance (optional).
config DataTableConfig Configuration object for feature toggles.
isLoading boolean Loading state for the table.
getRowId (row: TData, index: number) => string Custom function to get row IDs.
className string Additional CSS classes.
state Partial<TableState> Controlled table state (pagination, sorting, etc).
Name Type Description
onGlobalFilterChange (value: GlobalFilter) => void Called when global filter changes.
onPaginationChange (updater: Updater<PaginationState>) => void Called when pagination changes.
onSortingChange (updater: Updater<SortingState>) => void Called when sorting changes.
onColumnFiltersChange (updater: Updater<ColumnFiltersState>) => void Called when column filters change.
onColumnVisibilityChange (updater: Updater<ColumnVisibilityState>) => void Called when column visibility changes.
onRowSelectionChange (updater: Updater<RowSelectionState>) => void Called when row selection changes.
onExpandedChange (updater: Updater<ExpandedState>) => void Called when expanded state changes.
onColumnPinningChange (updater: Updater<ColumnPinningState>) => void Called when column pinning changes.
onColumnOrderChange (updater: Updater<ColumnOrderState>) => void Called when column order changes.
onRowSelection (selectedRows: TData[]) => void Called with selected row data.

The config prop takes a DataTableConfig object:

Name Type Default Description
enablePagination boolean false Turns on pagination. On automatically when DataTablePagination is used.
enableFilters boolean false Turns on filtering. On automatically when filter components are used.
enableSorting boolean false Turns on sorting. On automatically when sort components are used.
enableRowSelection boolean false Enable row selection.
enableMultiSort boolean true Enable multi-column sorting.
enableGrouping boolean false Turns on column grouping. On automatically when column group UI is used. Do not combine with tree getSubRows.
enableExpanding boolean false Enable row expansion.
manualSorting boolean false Enable server-side sorting.
manualPagination boolean false Enable server-side pagination.
manualFiltering boolean false Enable server-side filtering.
pageCount number - Total pages (required for server-side pagination).
initialPageSize number 10 Initial page size.
initialPageIndex number 0 Initial page index.
autoResetPageIndex boolean false Resets the page when filters or sorting change. Off by default (avoids flushSync warnings).
autoResetExpanded boolean false Auto-reset expanded rows on filter/sort change.
enableColumnResizing boolean false Turns on column resizing. On automatically when DataTableColumnResize is used.

The context provider DataTableRoot uses inside. Use it directly when you call useTable yourself and want to pass in your own table instance.

import { DataTableProvider } from "@/components/niko-table/core/data-table-context"
import { useTable } from "@tanstack/react-table"
import { features } from "@/components/niko-table/lib/data-table-features"
const table = useTable({ features, data, columns })
<DataTableProvider table={table} columns={columns} isLoading={false}>
{/* child components can use useDataTable() */}
</DataTableProvider>
Name Type Description
table DataTableInstance<TData> TanStack Table instance (required).
columns DataTableColumnDef<TData>[] Column definitions (optional).
isLoading boolean Loading state (optional).
children React.ReactNode Child components.

The raw React context object. Use it when you need to check whether a context exists (for example, to render conditionally).

import { DataTableContext } from "@/components/niko-table/core/data-table-context"
import { useContext } from "react"
const context = useContext(DataTableContext)

The table container. It wraps the table and handles scrolling.

import { DataTable } from "@/components/niko-table/core/data-table"
<DataTable className="rounded-md border" height={600}>
<DataTableHeader />
<DataTableBody />
</DataTable>
Name Type Default Description
className string - Extra CSS classes. Height classes (such as h-[600px]) are picked out and applied for you.
children React.ReactNode - Child components (Header, Body).
height number | string - Container height. Turns on vertical scrolling and scroll callbacks.
maxHeight number | string - Container max height. Defaults to height.

Draws the header, with sortable columns.

import { DataTableHeader } from "@/components/niko-table/core/data-table-structure"
<DataTableHeader sticky={true} />
Name Type Default Description
className string - Additional CSS classes.
sticky boolean true Makes the header sticky at the top when scrolling.

Draws the rows. Supports scroll events and row expansion.

import {
DataTableBody,
DataTableSkeleton,
DataTableEmptyBody,
} from "@/components/niko-table/core/data-table-structure"
<DataTableBody
onScroll={e => console.log(`Scrolled ${e.percentage}%`)}
onScrolledBottom={() => loadMore()}
>
<DataTableSkeleton />
<DataTableEmptyBody />
</DataTableBody>
Name Type Default Description
className string - Additional CSS classes.
children React.ReactNode - Child components (Skeleton, EmptyBody).
onScroll (event: ScrollEvent) => void - Scroll event handler.
onScrolledTop () => void - Called when scrolled to top.
onScrolledBottom () => void - Called when scrolled to bottom.
scrollThreshold number 50 Threshold for scroll events.
onRowClick (row: TData, event: React.MouseEvent<HTMLElement>) => void - Called when a row is clicked.
getRowMemoKey (row: TData) => string - A per-row key for state kept outside the table (inline edits, optimistic updates). When it changes, only that row re-renders. See Inline Edit Table.

Row memo invalidation: all six body components use React.memo for speed.

  • Column toggle, reorder and pin already refresh rows (the columnLayoutSignature prop covers them).
  • If a column cell reads external state (inline edit drafts, optimistic updates), set getRowMemoKey. Then only the changed row re-renders.

The ScrollEvent object passed to onScroll contains:

Property Type Description
scrollTop number Current scroll position from top.
scrollHeight number Total scrollable height.
clientHeight number Visible height of the container.
isTop boolean Whether scrolled to the top.
isBottom boolean Whether scrolled to the bottom.
percentage number Scroll percentage (0-100).

Shows a loading skeleton while isLoading is true. It matches your table’s shape.

<DataTableBody>
<DataTableSkeleton rows={5} />
</DataTableBody>
Name Type Default Description
rows number 5 Number of skeleton rows to display.
colSpan number - Number of columns (auto-detected if not provided).
className string - Additional CSS classes.
cellClassName string - CSS classes for skeleton cells.
skeletonClassName string - CSS classes for skeleton elements.
children React.ReactNode - Custom skeleton content (replaces rows).

Shows an empty state when there is no data. Build it from DataTableEmpty* components.

<DataTableBody>
<DataTableEmptyBody>
<DataTableEmptyIcon>
<PackageOpen className="size-12" />
</DataTableEmptyIcon>
<DataTableEmptyMessage>
<DataTableEmptyTitle>No products found</DataTableEmptyTitle>
<DataTableEmptyDescription>
Get started by adding your first product
</DataTableEmptyDescription>
</DataTableEmptyMessage>
<DataTableEmptyFilteredMessage>
No results match your filters
</DataTableEmptyFilteredMessage>
<DataTableEmptyActions>
<Button onClick={handleAdd}>Add Product</Button>
</DataTableEmptyActions>
</DataTableEmptyBody>
</DataTableBody>
Name Type Default Description
children React.ReactNode - Empty state composition components.
colSpan number - Number of columns (auto-detected if not provided).
className string - Additional CSS classes.

Shows a loading indicator while isLoading is true.

<DataTableBody>
<DataTableLoading>
<Spinner />
</DataTableLoading>
</DataTableBody>
Name Type Default Description
children React.ReactNode - Custom loading content.
colSpan number - Number of columns (auto-detected if not provided).
className string - Additional CSS classes.

A “loading more” row for infinite-scroll tables.

  • Shows: at the end of the body while isFetching is true. Renders nothing when false.
  • Where: a child of DataTableBody, next to DataTableSkeleton and DataTableEmptyBody.
  • Next page: use onScrolledBottom on the body to fetch it.
<DataTableBody
onScrolledBottom={() => {
if (hasMore && !isFetching) void loadMore()
}}
>
<DataTableSkeleton rows={10} />
<DataTableEmptyBody />
<DataTableLoadingMore isFetching={isFetching}>
Loading more products...
</DataTableLoadingMore>
</DataTableBody>

See Infinite Scroll Table for a complete working example.

Name Type Default Description
isFetching boolean - Required. Whether a next-page fetch is currently in flight. Self-gates on false.
children React.ReactNode "Loading more…" Custom label content (e.g. "Loading more products…").
colSpan number - Number of columns (auto-detected if not provided).
className string - Additional CSS classes on the spinner cell.

Catches errors in the table tree and shows a fallback UI.

import { DataTableErrorBoundary } from "@/components/niko-table/core/data-table-error-boundary"
<DataTableErrorBoundary
onError={(error, errorInfo) => {
console.error("Table error:", error)
trackError(error)
}}
>
<DataTableRoot data={data} columns={columns}>
{/* table components */}
</DataTableRoot>
</DataTableErrorBoundary>
Name Type Default Description
children React.ReactNode - Content to show when there is no error.
fallback React.ReactNode - Fallback UI shown on error.
onError (error: Error, errorInfo: React.ErrorInfo) => void - Called when an error is caught.
showResetButton boolean true Show a reset button.
resetButtonText string "Try Again" Custom reset button text.

For large datasets (1000+ rows), use the virtualized versions. They only render the visible rows.

Header for virtualized tables.

import {
DataTableVirtualizedHeader,
DataTableVirtualizedBody,
} from "@/components/niko-table/core/data-table-virtualized-structure"
<DataTable>
<DataTableVirtualizedHeader />
<DataTableVirtualizedBody estimateSize={34} overscan={20}>
{/* rows */}
</DataTableVirtualizedBody>
</DataTable>
Name Type Default Description
className string - Additional CSS classes.
sticky boolean true Makes the header sticky at the top when scrolling.

Body for virtualized tables. Handles thousands of rows.

Name Type Default Description
children React.ReactNode - Child components (VirtualizedSkeleton, VirtualizedEmptyBody).
estimateSize number 34 Estimated row height in pixels.
overscan number 20 Number of items to render outside visible area.
className string - Additional CSS classes.
onScroll (event: ScrollEvent) => void - Scroll event handler.
onScrolledTop () => void - Called when scrolled to top.
onScrolledBottom () => void - Called when scrolled to bottom (scroll-event-driven).
scrollThreshold number 50 Pixel threshold for scroll events.
onNearEnd () => void - Fires when the last rendered virtual row is within prefetchThreshold rows of the end. Driven by the virtualizer index, so it beats onScrolledBottom for infinite scroll.
prefetchThreshold number 10 How many rows from the end to trigger onNearEnd.
onRowClick (row: TData, event: React.MouseEvent) => void - Called when a row is clicked.
getRowMemoKey (row: TData) => string - A per-row key for state kept outside the table. When it changes, only that row (and its size measurement) re-renders.

Empty state for virtualized tables.

import {
DataTableVirtualizedBody,
DataTableVirtualizedEmptyBody,
} from "@/components/niko-table/core/data-table-virtualized-structure"
import {
DataTableEmptyIcon,
DataTableEmptyMessage,
DataTableEmptyTitle,
DataTableEmptyDescription,
} from "@/components/niko-table/components/data-table-empty-state"
import { PackageOpen } from "lucide-react"
<DataTableVirtualizedBody estimateSize={34}>
<DataTableVirtualizedEmptyBody>
<DataTableEmptyIcon>
<PackageOpen className="size-12" />
</DataTableEmptyIcon>
<DataTableEmptyMessage>
<DataTableEmptyTitle>No data found</DataTableEmptyTitle>
<DataTableEmptyDescription>
Get started by adding your first item
</DataTableEmptyDescription>
</DataTableEmptyMessage>
</DataTableVirtualizedEmptyBody>
</DataTableVirtualizedBody>
Name Type Default Description
children React.ReactNode - Empty state composition components.
colSpan number - Number of columns (auto-detected if not provided).
className string - Additional CSS classes.

Loading skeleton for virtualized tables.

import {
DataTableVirtualizedBody,
DataTableVirtualizedSkeleton,
} from "@/components/niko-table/core/data-table-virtualized-structure"
<DataTableVirtualizedBody estimateSize={34}>
<DataTableVirtualizedSkeleton rows={10} estimateSize={34} />
</DataTableVirtualizedBody>
Name Type Default Description
rows number 5 Number of skeleton rows to display.
estimateSize number 34 Estimated row height (should match VirtualizedBody).
className string - Additional CSS classes.
cellClassName string - CSS classes for skeleton cells.
skeletonClassName string - CSS classes for skeleton elements.
children React.ReactNode - Custom skeleton content.

Loading indicator for virtualized tables.

import {
DataTableVirtualizedBody,
DataTableVirtualizedLoading,
} from "@/components/niko-table/core/data-table-virtualized-structure"
import { Loader2 } from "lucide-react"
<DataTableVirtualizedBody estimateSize={34}>
<DataTableVirtualizedLoading>
<div className="flex items-center justify-center p-8">
<Loader2 className="size-6 animate-spin" />
<span className="ml-2">Loading...</span>
</div>
</DataTableVirtualizedLoading>
</DataTableVirtualizedBody>
Name Type Default Description
children React.ReactNode - Custom loading content.
colSpan number - Number of columns (auto-detected if not provided).
className string - Additional CSS classes.

The virtualized version of DataTableLoadingMore, for infinite-scroll virtualized tables.

  • Outside the row count: it is a plain child of TableBody, not a virtual row.
  • No size impact: it does not affect the estimateSize math.
import {
DataTableVirtualizedBody,
DataTableVirtualizedSkeleton,
DataTableVirtualizedEmptyBody,
DataTableVirtualizedLoadingMore,
} from "@/components/niko-table/core/data-table-virtualized-structure"
<DataTableVirtualizedBody
prefetchThreshold={15}
onNearEnd={() => {
if (hasMore && !isFetching) void loadMore()
}}
>
<DataTableVirtualizedSkeleton rows={15} />
<DataTableVirtualizedEmptyBody />
<DataTableVirtualizedLoadingMore isFetching={isFetching}>
Loading more products...
</DataTableVirtualizedLoadingMore>
</DataTableVirtualizedBody>

See Infinite Scroll Virtualized Table for a complete working example.

Name Type Default Description
isFetching boolean - Required. Whether a next-page fetch is currently in flight. Self-gates on false.
children React.ReactNode "Loading more…" Custom label content (e.g. "Loading more products…").
colSpan number - Number of columns (auto-detected if not provided).
className string - Additional CSS classes on the spinner cell.

Pick the DnD components for your case:

Use Case Components
Row reorder (standard) DataTableDndBody
Column reorder (standard) DataTableDndHeader + DataTableDndColumnBody
Row reorder (virtualized) DataTableVirtualizedDndBody
Column reorder (virtualized) DataTableVirtualizedDndHeader + DataTableVirtualizedDndColumnBody

Row and column DnD are separate modules. Installing one does not install the other. They replace DataTableHeader and DataTableBody directly.

Table body with draggable rows. Use it in place of DataTableBody for row drag-and-drop.

  • Needs: a DataTableRowDndProvider around it.
  • Registry: data-table-row-dnd.
import { DataTableDndBody } from "@/components/niko-table/core/data-table-row-dnd-structure"
import { DataTableRowDndProvider } from "@/components/niko-table/components/data-table-row-dnd"
<DataTableRowDndProvider data={data} onReorder={setData}>
<DataTable>
<DataTableHeader />
<DataTableDndBody />
</DataTable>
</DataTableRowDndProvider>
Name Type Default Description
children React.ReactNode - Child components.
className string - Additional CSS classes.
onRowClick (row: TData, event: React.MouseEvent<HTMLElement>) => void - Called when a row is clicked.
getRowMemoKey (row: TData) => string - Per-row key encoding external row state. When it changes for a row, only that row re-renders.

Table header with draggable columns. Use it in place of DataTableHeader for column drag-and-drop.

  • Needs: a DataTableColumnDndProvider around it.
  • Registry: data-table-column-dnd.
import { DataTableDndHeader, DataTableDndColumnBody } from "@/components/niko-table/core/data-table-column-dnd-structure"
import { DataTableColumnDndProvider } from "@/components/niko-table/components/data-table-column-dnd"
<DataTableColumnDndProvider columnOrder={columnOrder} onColumnOrderChange={setColumnOrder}>
<DataTable>
<DataTableDndHeader />
<DataTableDndColumnBody />
</DataTable>
</DataTableColumnDndProvider>
Name Type Default Description
className string - Additional CSS classes.
sticky boolean true Makes the header sticky at the top when scrolling.

Table body for column drag-and-drop. Each cell follows its column’s drag position (via useSortable). Needs a DataTableColumnDndProvider around it.

Name Type Default Description
children React.ReactNode - Child components.
className string - Additional CSS classes.
onRowClick (row: TData, event: React.MouseEvent<HTMLElement>) => void - Called when a row is clicked.
getRowMemoKey (row: TData) => string - Per-row key encoding external row state. When it changes for a row, only that row re-renders.

Virtualized DnD is split by axis the same way. Registry: data-table-virtualized-row-dnd / data-table-virtualized-column-dnd (plus data-table-virtualized and the matching non-virtualized axis package).

Virtualized body for row drag-and-drop. It pairs @tanstack/react-virtual (windowing) with @dnd-kit/sortable (dragging). Needs a DataTableRowDndProvider around it.

import { DataTableVirtualizedFlexHeader, DataTableVirtualizedEmptyBody } from "@/components/niko-table/core/data-table-virtualized-structure"
import { DataTableVirtualizedDndBody } from "@/components/niko-table/core/data-table-virtualized-row-dnd-structure"
import { DataTableRowDndProvider } from "@/components/niko-table/components/data-table-row-dnd"
<DataTableRowDndProvider data={data} onReorder={setData}>
<DataTable height={500}>
<DataTableVirtualizedHeader />
<DataTableVirtualizedDndBody estimateSize={40} overscan={10}>
<DataTableVirtualizedEmptyBody />
</DataTableVirtualizedDndBody>
</DataTable>
</DataTableRowDndProvider>
Name Type Default Description
children React.ReactNode - Child components (e.g. DataTableVirtualizedEmptyBody).
estimateSize number 34 Estimated row height in pixels.
overscan number 20 Number of items to render outside visible area.
className string - Additional CSS classes.
onScroll (event: ScrollEvent) => void - Scroll event handler.
onScrolledTop () => void - Called when scrolled to top.
onScrolledBottom () => void - Called when scrolled to bottom.
scrollThreshold number 50 Pixel threshold for top/bottom scroll events.
onRowClick (row: TData, event: React.MouseEvent) => void - Called when a row is clicked.
getRowMemoKey (row: TData) => string - Per-row key encoding external row state. When it changes for a row, only that row re-renders.

Virtualized header for column drag-and-drop. Needs a DataTableColumnDndProvider around it.

import {
DataTableVirtualizedDndHeader,
DataTableVirtualizedDndColumnBody,
} from "@/components/niko-table/core/data-table-virtualized-column-dnd-structure"
import { DataTableColumnDndProvider } from "@/components/niko-table/components/data-table-column-dnd"
<DataTableColumnDndProvider columnOrder={columnOrder} onColumnOrderChange={setColumnOrder}>
<DataTable height={500}>
<DataTableVirtualizedDndHeader />
<DataTableVirtualizedDndColumnBody estimateSize={40} />
</DataTable>
</DataTableColumnDndProvider>
Name Type Default Description
className string - Additional CSS classes.
sticky boolean true Makes the header sticky at the top when scrolling.

Virtualized body for column drag-and-drop. Each cell follows its column’s drag position (via useSortable). Needs a DataTableColumnDndProvider around it.

Name Type Default Description
children React.ReactNode - Child components (e.g. DataTableVirtualizedEmptyBody).
estimateSize number 34 Estimated row height in pixels.
overscan number 20 Number of items to render outside visible area.
className string - Additional CSS classes.
onScroll (event: ScrollEvent) => void - Scroll event handler.
onScrolledTop () => void - Called when scrolled to top.
onScrolledBottom () => void - Called when scrolled to bottom.
scrollThreshold number 50 Pixel threshold for top/bottom scroll events.
onRowClick (row: TData, event: React.MouseEvent) => void - Called when a row is clicked.