Komdes
Components

Data Table

A powerful and flexible data table component for displaying, filtering, sorting, and paginating tabular data.

Reference the TanStack Table Column Definitions Guide for detailed column definition guide.

Features

  • Advanced Filtering - Multiple filter types (text, number, date, select, multi-select) with customizable operators
  • URL State Management - Sync table state with URL search params using nuqs
  • Sorting - Multi-column sorting with persistent state
  • Pagination - Server-side or client-side pagination with customizable page sizes
  • Column Visibility - Toggle column visibility with view options menu
  • Row Selection - Single or multi-row selection with action bar
  • Column Pinning - Pin columns to left or right for better UX
  • Keyboard Navigation - Full keyboard support with shortcuts for filter and sort menus
  • Responsive - Mobile-first design with overflow handling
  • Customizable - Flexible API for custom filters, columns, and actions

Layout

Import all components and combine them:

Walkthrough

Define columns with appropriate metadata:

Initialize the table state using the useDataTable hook:

Pass the table instance to the DataTable, and DataTableToolbar components:

Render an action bar on row selection:

API Reference

Column Definitions

The column definitions are used to define the columns of the data table.

Properties

Core configuration options for defining columns.

PropDescription
idRequired: Unique identifier for the column
accessorKeyRequired: Key to access the data from the row
accessorFnOptional: Custom accessor function to access data
headerOptional: Custom header component with column props
cellOptional: Custom cell component with row props
metaOptional: Meta options for accessing column metadata
enableColumnFilterBy default, the column will not be filtered. Set to `true` to enable filtering
enableSortingEnable sorting for this column
enableHidingEnable column visibility toggle

Column Meta

Column meta options for filtering, sorting, and view options.

PropDescription
labelThe display name for the column
placeholderThe placeholder text for filter inputs
variantThe type of filter to use (`text`, `number`, `select`, etc.)
optionsFor select/multi-select filters, an array of options with `label`, `value`, and optional `count` and `icon`
rangeFor range filters, a tuple of `[min, max]` values
unitFor numeric filters, the unit to display (e.g., 'hr', '$')
iconThe react component to use as an icon for the column

Filter Variants

Available filter variants for column meta.

TitleDescription
textText search with contains, equals, etc.
numberNumeric filters with equals, greater than, less than, etc.
rangeRange filters with minimum and maximum values
dateDate filters with equals, before, after, etc.
dateRangeDate range filters with start and end dates
booleanBoolean filters with true/false values
selectSingle-select filters with predefined options
multiSelectMulti-select filters with predefined options

useDataTable

A hook for initializing the data table with state management.

Overview

The useDataTable hook acts as an intelligent wrapper around useReactTable from @tanstack/react-table. It seamlessly handles:

  • Server-side pagination, sorting, and filtering
  • Controlled or uncontrolled state for page and page size
  • Debounced column filter updates (defaults to 300ms) to prevent excessive API calls
  • Row selection and column visibility management

Import

Usage

Basic Setup

First, define your columns. Use the meta property to configure filter behaviors.

When fetching data from an external API, it's highly recommended to control the pagination state externally.

Uncontrolled Pagination

If you don't provide page, perPage, or onPageChange, the hook will manage the state internally.

Column Filtering

Column filtering is enabled by setting enableColumnFilter: true in your column definitions. The filterValues returned by the hook contains the active filter key-value pairs that can be sent directly to your API:

Props

The useDataTable hook accepts the following properties.

Prop

Type

Returns

The useDataTable hook returns an object with the following properties.

Prop

Type

Column Meta for Filter Variant

Utilize the meta property in your column definitions to configure the UI representation of the filter:

Loading State (DataTableSkeleton)

DataTableSkeleton is used to display a loading skeleton that strictly matches the actual layout of the data table. This is extremely useful when combined with React.Suspense or when awaiting data from an API.

Skeleton Usage

Suspense Integration

The recommended pattern when using frameworks like Next.js or React Router v7 with asynchronous data fetching:

Skeleton Props

PropTypeDefaultDescription
columnCountnumberRequired. The number of columns the skeleton should render.
rowCountnumber10The number of row skeletons to display.
filterCountnumber0The number of filter skeleton boxes to display in the top toolbar.
cellWidthsstring[]['auto']An array of column widths (e.g., ['100px', '200px']).
withViewOptionsbooleantrueWhether to render the skeleton for the column visibility toggle button.
withPaginationbooleantrueWhether to render the skeleton for the bottom pagination controls.
shrinkZerobooleanfalseIf true, columns will possess a min-width matching their respective cellWidths.
classNamestringCustom CSS class for the main container.

How is this guide?

On this page