Skip to content
Niko Table

TypeScript Types

Every TypeScript type and interface used by the data table.

types.ts holds the TypeScript types used across the data table.

An option in a select or multi-select filter.

interface Option {
label: string
value: string
count?: number
icon?: React.ComponentType<{ className?: string }>
}

Sets which UI control a filter uses.

type FilterVariant =
| "text"
| "number"
| "range"
| "date"
| "dateRange"
| "select"
| "multiSelect"
| "boolean"

Sets how a filter compares values.

type FilterOperator =
| "ilike"
| "not.ilike"
| "eq"
| "neq"
| "in"
| "not.in"
| "empty"
| "not.empty"
| "lt"
| "lte"
| "gt"
| "gte"
| "between"
| "relative"

Sets how several filters combine.

type JoinOperator = "and" | "or" | "mixed"

A column filter with extra metadata.

interface ExtendedColumnFilter<TData> {
id: Extract<keyof TData, string>
value: string | string[]
variant: FilterVariant
operator: FilterOperator
filterId: string
joinOperator?: JoinOperator // Individual join operator for each filter
}

A column sort, used for URL state.

interface ExtendedColumnSort<TData> {
id: Extract<keyof TData, string>
desc: boolean
}

The global (search) filter value.

type GlobalFilter = string | Record<string, unknown>

The column definition type. It has every TanStack Table ColumnDef property.

type DataTableColumnDef<TData, TValue = unknown> = ColumnDef<
DataTableFeatures,
TData,
TValue
>

For static columns, use createDataTableColumnHelper<TData>().

  • Same binding: it pre-binds DataTableFeatures, like this alias.
  • Typed cells: getValue() is typed.
  • Mixed value types: helper results mix per-column value types. Pass them as DataTableColumns<TData> (what DataTableRoot accepts).
  • Plain arrays: DataTableColumnDef<TData>[] fits dynamic columns and copy-paste examples better.
import { createDataTableColumnHelper } from "@/components/niko-table/lib/data-table-features"
const columnHelper = createDataTableColumnHelper<Product>()
const columns = [
columnHelper.accessor("price", {
cell: ({ getValue }) => getValue().toFixed(2),
}),
]

The column array type for DataTableRoot. Helper columns each have their own TValue, so they do not fit DataTableColumnDef<TData>[] (its TValue defaults to unknown). Use this alias instead.

type DataTableColumns<TData> = DataTableColumnDef<TData, any>[]

Extra column metadata. It adds to TanStack Table’s ColumnMeta.

interface ColumnMeta<TData extends RowData, TValue> {
// Display
label?: string
placeholder?: string
// Filtering
variant?: FilterVariant
options?: Option[]
range?: [number, number]
autoOptions?: boolean
autoOptionsFormat?: boolean
/** Per-column label formatter for auto-derived faceted-filter options.
* Wins over `autoOptionsFormat`; ignored when caller passes explicit `options`. */
formatOptionLabel?: (value: string) => string
showCounts?: boolean
dynamicCounts?: boolean
mergeStrategy?: "preserve" | "augment" | "replace"
// Formatting
unit?: string
icon?: React.ComponentType<{ className?: string }>
// Layout
/** Controls which column absorbs leftover row width (flex fill).
* Fill is on by default for resizable tables — the first non-pinned,
* resizable data column flexes automatically. Set `true` to make THIS
* column the one that fills instead of the default; set `false` to opt a
* column out of ever being auto-picked. Pure layout — never written to
* `columnSizing`. */
flex?: boolean
// Row Expansion
expandedContent?: (row: TData) => React.ReactNode
}

Extra table metadata. It adds to TanStack Table’s TableMeta.

interface TableMeta<TData extends RowData> {
joinOperator?: JoinOperator
hasIndividualJoinOperators?: boolean
/** Turns flex fill off for the whole table. Flex fill (the first resizable
* data column absorbing leftover row width) is on by default when column
* resizing is enabled; set `true` for a wide table meant to scroll
* horizontally rather than fill its container. */
disableFlexFill?: boolean
}

Pass table metadata through the table-level meta option on DataTableRoot, not a column’s meta:

<DataTableRoot data={data} columns={columns} meta={{ disableFlexFill: true }}>

disableFlexFill is read when the table options are built. Set it statically, not at runtime.

A row. Alias for TanStack Table’s Row, bound to DataTable’s features.

type DataTableRow<TData> = Row<DataTableFeatures, TData>

The table instance. Alias for TanStack Table’s Table, bound to DataTable’s features.

type DataTableInstance<TData> = Table<DataTableFeatures, TData>

Names of the URL query keys.

interface QueryKeys {
page?: string
perPage?: string
sort?: string
filters?: string
joinOperator?: string
}

Gets the literal values of a constant object.

type ValueOf<T> = T[keyof T]

The values of the JOIN_OPERATORS constant.

type JoinOperatorValues = typeof JOIN_OPERATORS

The values of the FILTER_OPERATORS constant.

type FilterOperatorValues = typeof FILTER_OPERATORS

The values of the FILTER_VARIANTS constant.

type FilterVariantValues = typeof FILTER_VARIANTS

This module adds custom metadata to TanStack Table’s types:

  • ColumnMeta: adds label, placeholder, variant, options, flex (layout fill), and other filter metadata
  • TableMeta: adds joinOperator and hasIndividualJoinOperators (filter logic), and disableFlexFill (layout)

TypeScript can then check and autocomplete column and table metadata.