Property-backed columns
Define fields read directly from typed row objects.
TanStack · Type Alias
ColumnDef is TanStack Table's union type for describing display, group, and accessor columns. Its generics type the feature set, row data, and cell values.
ColumnDef is a union describing a table column: a display column, a group column containing child definitions, or an accessor column that extracts row data. Its generics specify the table features, row type, and cell-value type.
type ColumnDef<TFeatures, TData, TValue> = DisplayColumnDef<TFeatures, TData, TValue> | GroupColumnDef<TFeatures, TData, TValue> | AccessorColumnDef<TFeatures, TData, TValue>;| Name | Type | Description |
|---|---|---|
TFeatures | extends TableFeatures | The enabled table feature set used by the definition types. |
TData | extends RowData | The row-data type used by the table. |
TValue | extends CellData = CellData | The cell-value type; defaults to CellData. |
A union type for display, group, and accessor column definitions; it does not define a runtime return value.
import type { ColumnDef } from '@tanstack/react-table'
type Person = { firstName: string; age: number }
const columns: ColumnDef<Person>[] = [
{ accessorKey: 'firstName', header: 'First name' },
{ accessorKey: 'age', header: 'Age' },
]Defines typed table columns by mapping row-object keys to displayed headers.
Define fields read directly from typed row objects.
Build values derived from multiple row fields.
Arrange related columns under a shared heading.
Attach application-specific configuration to columns.
ColumnDef<TFeatures, TData, TValue> is a union of display, group, and accessor column definitions. TFeatures describes enabled table features, TData is the row type, and TValue defaults to CellData.
Follow-up: How would you model a computed column? Use an accessor column with accessorFn, whose function receives the original row and index and returns the value.
Use accessorKey when the value comes directly from a row property. Use accessorFn when the value must be computed from the original row.
Follow-up: What information does an accessorFn receive? It receives originalRow: TData and index: number, and returns any.
A column definition can include header, footer, and cell render templates. A template may be a string or a function receiving the relevant context, with the exact rendered result depending on the adapter.
Follow-up: Where can column metadata be read? Through column.columnDef.meta whenever the column is available.
ColumnDefTemplateColumn APIsTable APIsAccessorColumnDefDisplayColumnDefGroupColumnDef