Columns
Preview

Configure DataGrid columns, header actions, and presentation.

Overview

Define stable columns with createDataGridColumnHelper. Column definitions control content, sizing, available header actions, and accessibility metadata. Configure merged layouts in the advanced Cell Spanning guide.

String headers automatically show actions based on their column settings. Disable actions that do not make sense for a column, such as hiding on a primary identifying or action column. For custom headers, enable the menu with meta.headerMenu and provide its accessible name with meta.headerLabel.

Set meta.rowHeader on the primary identifying column and use meta.align for content alignment. Columns share available width equally by default, so most columns should omit both flex and size. Use flex only when a column needs a different proportional share, such as a primary name column. Reserve size for exact-width utility columns such as selection or actions. flex and size are mutually exclusive, while minSize and maxSize bound both automatic fitting and manual resizing.

Column resizing is opt-in. A resized column keeps its pixel width until sizing is reset. The grid scrolls horizontally when exact widths and flexible minimum widths no longer fit the viewport.

Use useDataGridView when visibility, order, or pinning belongs to a saved view. Column sizing remains responsive to the current viewport. See Saved Views.

Examples

Sizing and resizing

Omit flex and size for an equal share, use flex for intentional weighting, and use size for an exact pixel width. Set minSize and maxSize wherever a column needs readable bounds. Enable resizing on the table and use enableResizing: false for columns that should not resize.

Reordering

Set enableColumnReordering to add Move left and Move right header actions. Add enableColumnDragging when drag handles are also required; dragging has no effect unless reordering is enabled.

Visibility

Hideable columns appear in the header's Columns submenu. Keep identifying and action columns visible with enableHiding: false.

Pinning

Eligible columns expose Pin to left and Pin to right header actions. Use initialState.columnPinning when columns should start pinned; start pins left and end pins right.

Sorting

Configure sortable columns with sortFn and enableSorting. DataGrid adds Asc and Desc header actions and lets users clear the active direction.

Filtering with Filters

Use Cubitt Filters for product-facing filtering. useDataGridFilters prepares the columns and table options; pass both results to useDataGridTable and adapt the resulting table with useDataGridFiltersControl. See Filters for filtering strategies, options, and advanced field mappings.

API Reference

Table options

OptionTypeDefaultDescription
enableColumnResizingbooleanfalseEnables column resize controls.
columnResizeMode"onChange" | "onEnd""onEnd"Controls whether widths update during or after resizing.
columnResizeDirection"ltr" | "rtl""ltr"Sets the direction used to calculate resize drag offsets.
enableColumnReorderingbooleanfalseAdds Move left and Move right actions to eligible columns.
enableColumnDraggingbooleanfalseAdds drag handles when reordering is enabled.
enableHidingbooleantrueAllows eligible columns to appear in the Columns submenu.
enableColumnPinningbooleantrueAllows eligible columns to expose start and end pin actions.
enableSortingbooleantrueAllows accessor columns to expose sorting actions.

Column options

OptionTypeDefaultDescription
flexnumber1 when size is omittedRelative share of available width. Must be greater than zero.
sizenumberundefinedExact column width in pixels. Cannot be combined with flex.
minSizenumber20Minimum width for automatic fitting and manual resizing.
maxSizenumberNumber.MAX_SAFE_INTEGERMaximum width for automatic fitting and manual resizing.
enableResizingbooleanTable settingEnables or disables resizing for this column.
enableColumnReorderingbooleanTable settingOverrides reordering for this column.
enableHidingbooleantrueAllows this column to be hidden.
enablePinningbooleantrueAllows this column to be pinned.
enableSortingbooleantrueAllows this accessor column to be sorted.
sortFnSortFnOption<DataGridFeatures, TData>"auto"Selects or supplies the comparison function.
filterFnFilterFnOption<DataGridFeatures, TData>"auto"Selects or supplies a custom filter function when Cubitt Filters is not used.

Table methods

APISignatureDescription
table.resetColumnSizing(defaultState?) => voidRestores initial widths, or clears sizing state when passed true.
table.resetColumnOrder(defaultState?) => voidRestores the initial column order, or the definition order when passed true.
table.resetColumnVisibility(defaultState?) => voidRestores initial visibility, or shows every eligible column when passed true.
table.resetColumnPinning(defaultState?) => voidRestores initial pinning, or unpins every column when passed true.
table.resetSorting(defaultState?) => voidRestores initial sorting, or clears it when passed true.

Column helpers

APISignatureDescription
columnHelper.group(options: GroupColumnDef) => GroupColumnDefCreates a grouped header without grouping rows.
useDataGridFilters(options: UseDataGridFiltersOptions) => UseDataGridFiltersResultPrepares columns and table options for Cubitt Filters.
useDataGridFiltersControl(table: DataGridTable<TData>) => UseDataGridFiltersControlResultAdapts a configured table into Filters.Root props and current facet options.

Column metadata

FieldTypeDefaultDescription
headerLabelstring-Plain-text name for accessibility and menu copy when the rendered header is not a string.
headerMenubooleanAutomaticString headers include a menu when actions are available. Set true on a compatible custom header or false to disable the menu.
align"start" | "center" | "end""start"Aligns header and body content.
rowHeaderbooleanfalseRenders body cells as accessible row headers. Use for the primary identifying column.

On this page