Columns

Column definitions, stable ids, renderers, and DataTable-specific column metadata.

Overview

Columns are the contract between your row data and DataTable. Cubitt accepts standard TanStack ColumnDef objects, then reads a small set of additional metadata for features like loading states and inline edit.

Stable Column Ids

Features like column visibility, filtering, pinning, and controlled state all work best when every interactive column has a stable id.

const columns: ColumnDef<Employee>[] = [
  {
    id: "name",
    header: "Name",
    accessorKey: "name",
    enableHiding: false,
  },
  {
    id: "status",
    header: "Status",
    accessorKey: "status",
  },
];

If you omit id, TanStack can often infer one from a string accessorKey. That is fine for simple cases, but explicit ids are easier to reason about once the table grows.

Accessors and Renderers

Use accessorKey for direct field access, accessorFn when the displayed value is derived, and cell when the rendered output needs custom UI.

const columns: ColumnDef<Employee>[] = [
  {
    id: "name",
    header: "Name",
    accessorKey: "name",
    cell: ({ row }) => <span className="font-medium">{row.getValue("name")}</span>,
  },
  {
    id: "status",
    header: "Status",
    accessorKey: "status",
    cell: ({ row }) => (
      <Badge variant={row.getValue("status") === "Active" ? "brand" : "secondary"}>
        {String(row.getValue("status"))}
      </Badge>
    ),
  },
];

DataTable Column Metadata

DataTable reads two ColumnDef.meta fields directly:

  • meta.skeleton customizes the loading skeleton for that column
  • meta.editable marks a column editable when inline edit mode is enabled
const columns: ColumnDef<Employee>[] = [
  {
    id: "name",
    header: "Name",
    accessorKey: "name",
    meta: {
      skeleton: () => <Skeleton className="h-4 w-24" />,
      editable: true,
    },
  },
];

This page only covers the ColumnDef fields that matter most when using Cubitt's DataTable. For the full upstream surface, see TanStack's Column Def guide, Column Def API, Column Sizing API, and Column Visibility API.

API Reference

Common ColumnDef Fields

FieldTypeDescription
idstringStable column id used by controlled table features
headerstring | ReactNode | render fnHeader content
accessorKeykeyof TDataRead a value directly from the row object
accessorFn(row: TData) => unknownDerive a value from the row object
cellrender fnCustom cell renderer
columnsColumnDef<TData>[]Nested child columns for grouped headers
sizenumberInitial column width
minSizenumberMinimum column width. Defaults to 50 in DataTable
maxSizenumberMaximum column width for TanStack sizing
enableHidingbooleanTanStack column-visibility flag. Set false to keep a column always visible
enableSortingbooleanOverride whether a specific column can be sorted
enableResizingbooleanOverride whether a specific column can be resized
enablePinningbooleanOverride whether a specific column can be pinned

DataTable-specific meta

FieldTypeDescription
meta.skeleton() => ReactNodeCustom loading skeleton for that column
meta.editablebooleanMarks the column editable for inline edit mode
PropTypeDescription
dataTData[]Row objects rendered against the column definitions
columnsColumnDef<TData>[]Column definitions passed into DataTable

On this page