
Description
Control TanStack Table v9 leaf columnOrder with stable IDs while accounting for pinning regions, visibility, and groupedColumnMode precedence. Load for drag-and-drop columns or rendered order that differs from state.
SKILL.md
This skill builds on core and table-features. columnOrder orders unpinned leaf IDs; other plugins can still determine the final visual regions.
Setup
import { columnOrderingFeature, tableFeatures } from '@tanstack/table-core'
export const features = tableFeatures({ columnOrderingFeature })
export const initialState = { columnOrder: ['name', 'age', 'actions'] }
Core Patterns
const next = columnOrder.filter((id) => id !== activeId)
next.splice(next.indexOf(overId), 0, activeId)
table.setColumnOrder(next)
Use column IDs as drag identities and replace the array.
Common Mistakes
HIGH Assuming state is final order
Wrong: renderIds(columnOrder)
Correct: renderColumns(table.getAllLeafColumns())
Pinning regions and grouping mode apply after base ordering. If
columnVisibilityFeature is also registered, render
table.getVisibleLeafColumns() to apply visibility too.
Source: docs/framework/react/guide/column-ordering.md#what-affects-column-order
HIGH Using labels as identities
Wrong: const activeId = column.columnDef.header as string
Correct: const activeId = column.id
Headers can collide or change; ordering state stores stable leaf column IDs.
Source: packages/table-core/src/features/column-ordering/columnOrderingFeature.types.ts
HIGH Mutating controlled state in place
Wrong: columnOrder.splice(0, 1); table.setColumnOrder(columnOrder)
Correct: table.setColumnOrder(columnOrder.slice(1))
Reactive owners commonly require a new array reference.
Source: examples/react/column-dnd/src/main.tsx
API Discovery
Inspect node_modules/@tanstack/table-core/dist/features/column-ordering/; combine with pinning/visibility skills when those plugins are registered.
More skills from the table repository
View all 30 skillsaggregation
perform data aggregation in TanStack Table
Jul 26Data AnalysisFrontendTanStackapi-not-found
diagnose TanStack Table API errors
Jul 26DebuggingFrontendTanStackcell-selection
select rectangular cell ranges in tables
Jul 26Data AnalysisTanStackUI Componentsclient-vs-server
manage TanStack Table data pipelines
Jul 26Data PipelineFrontendPerformanceTanStackcolumn-faceting
build faceted filter UIs
Jul 26Data VisualizationFrontendTanStackcolumn-filtering
implement column filtering in TanStack Table
Jul 26Data AnalysisFrontendTanStack
More from TanStack
View publishercolumn-pinning
configure column pinning in TanStack Table
table
Jul 26CSSFrontendTanStackUI Componentscolumn-resizing
implement column resizing in TanStack Table
table
Jul 26FrontendTanStackUI Componentscolumn-sizing
configure column sizing in TanStack Table
table
Jul 26CSSFrontendTanStackUI Componentscolumn-visibility
manage column visibility in TanStack Table
table
Jul 26FrontendTanStackUI Componentscore
build data grids with TanStack Table
table
Jul 26Data AnalysisFrontendUI Components