Strongly typed data columns
Build columns whose value types follow row-property keys or accessor callbacks.
TanStack · Function
Creates a typed helper for authoring TanStack Table column definitions. It improves inference for accessor values, display and group columns, and arrays of nested definitions.
Call createColumnHelper with the table feature type and row type to obtain utilities for building strongly inferred column definitions. Its methods create accessor, display, group, and array-wrapping definitions; at runtime, the helper only produces column-definition objects.
createColumnHelper<TFeatures, TData>(): ColumnHelper<TFeatures, TData>| Name | Type | Description |
|---|---|---|
TFeatures | TFeatures extends TableFeatures | The table feature configuration type, constrained to TableFeatures; commonly supplied as typeof features. |
TData | TData extends RowData | The row-data type used by the table. |
ColumnHelper<TFeatures, TData>
import { createColumnHelper, tableFeatures } from '@tanstack/react-table'
type Person = { firstName: string; age: number }
const features = tableFeatures({})
const helper = createColumnHelper<typeof features, Person>()
const columns = helper.columns([
helper.accessor('firstName', { header: 'First name' }),
helper.accessor(row => row.age, { id: 'age', header: 'Age' }),
helper.display({ id: 'actions', header: 'Actions' }),
])
console.log(columns)Creates typed accessor and display column definitions, then wraps the array to preserve individual value types.
Build columns whose value types follow row-property keys or accessor callbacks.
Represent actions, selection controls, or other cells without a row data value.
Organize leaf columns into nested headers while retaining precise array types.
createColumnHelper<TFeatures, TData>() returns a ColumnHelper<TFeatures, TData>. It provides utilities for authoring column definitions with stronger value inference, especially for accessor values.
Follow-up: What happens at runtime? The helper does not add table behavior; it returns column-definition objects.
accessor builds data columns from a key or accessor function, display builds non-data columns, and group builds parent columns containing nested columns. The columns method wraps an array so individual value types are preserved.
Follow-up: When would columns be especially useful? Use it for nested groups or heterogeneous column arrays where plain array inference loses precision.
The function takes TFeatures, extending TableFeatures, and TData, extending RowData. In the current API, the feature type normally comes from typeof features, while TData is the row shape.
Follow-up: How does the factory differ when using createTableHook? Its returned createAppColumnHelper is already bound to the feature type, so only TData is supplied.
ColumnHelperColumnDeftableFeaturescreateTableHookaccessordisplaygroupcolumns