useTableColumnSettingsState@astryxdesign/core v0.7.12 · useTableColumnSettingsState

Usage

Headless column visibility and ordering state management for Table. Manages which columns are active, provides toggle and reset operations, and produces a config object that feeds directly into useTableColumnSettings. Renderer-agnostic and pairs with any column picker UI.

ts
import {useTableColumnSettingsState} from '@astryxdesign/core'

Best practices

GuidancePractices
Do

Pass columnSettingsConfig directly to useTableColumnSettings and give the resulting plugin to Table.

Do

Mark essential identifier columns (like name or ID) with isAlwaysVisible: true so users cannot accidentally hide them.

Don't

Mutate activeColumnKeys array directly; use toggleColumn, showAllColumns, or resetToDefault.

Parameters

ParamTypeDescription
configrequired
<TColumnKey>

The columns to configure and active keys state management.

config.columnsrequired
ReadonlyArray<
<TColumnKey>>

All available columns with metadata (key, label, isAlwaysVisible, group) for the settings UI.

config.activeColumnKeysrequired
ReadonlyArray<TColumnKey>

Currently active column keys, in display order. Only columns in this list render in the table.

config.onChangeActiveColumnKeysrequired
(keys: ReadonlyArray<TColumnKey>) => void

Called when active columns change (via toggle, show all, or reset) to update consumer state.

config.defaultColumnKeys
ReadonlyArray<TColumnKey>

Default column set restored by resetToDefault. When omitted, resetToDefault activates all columns.

Returns

FieldTypeDescription
columnSettingsConfig
<TColumnKey>

Ready-to-use config to pass directly to useTableColumnSettings(columnSettingsConfig).

activeColumnKeysReadonlyArray<TColumnKey>

Pass-through of currently active column keys in display order.

toggleColumn(key: TColumnKey) => void

Toggles column visibility: removes an active column or appends an inactive column. No-op for isAlwaysVisible columns.

isColumnActive(key: TColumnKey) => boolean

Whether a specific column is currently in the active column keys list.

isColumnToggleable(key: TColumnKey) => boolean

Whether a specific column can be toggled (returns false if isAlwaysVisible is true).

showAllColumns() => void

Activates all configured columns in the table.

resetToDefault() => void

Resets active column keys to defaultColumnKeys (or all columns if defaultColumnKeys is omitted).

setActiveColumnKeys(keys: string[]) => void

Sets active column keys from a list of key strings, enforcing that isAlwaysVisible columns remain active.

Examples

Common configurations, variations, and states.
useTableColumnSettingsState — Column Visibility Picker
Open in Playground

A Table toolbar with a Columns menu of checkboxes: toggling Email updates active columns, Reset restores defaults, and the config is passed directly to useTableColumnSettings.

Use with shadcn

Already using the shadcn registry workflow? Install the real Astryx package and a local public re-export. Component implementation source stays in Astryx.

This install URL expires with the draft preview.
bash
npx shadcn@4.19.0 add https://astryx-p6p2hnh7y-fbopensource.vercel.app/shadcn/hooks/use-table-column-settings-state.json