Column Sizing
The ability to resize columns by dragging the column header border.
State
Column sizing state is stored on the table using the following shape:
export type ColumnSizingTableState = {
  columnSizing: ColumnSizing
  columnSizingInfo: ColumnSizingInfoState
}
 
export type ColumnSizing = Record<string, number>
 
export type ColumnSizingInfoState = {
  startOffset: null | number
  startSize: null | number
  deltaOffset: null | number
  deltaPercentage: null | number
  isResizingColumn: false | string
  columnSizingStart: [string, number][]
}export type ColumnSizingTableState = {
  columnSizing: ColumnSizing
  columnSizingInfo: ColumnSizingInfoState
}
 
export type ColumnSizing = Record<string, number>
 
export type ColumnSizingInfoState = {
  startOffset: null | number
  startSize: null | number
  deltaOffset: null | number
  deltaPercentage: null | number
  isResizingColumn: false | string
  columnSizingStart: [string, number][]
}Column Def Options
enableResizing
enableResizing?: booleanenableResizing?: booleanEnables or disables column resizing for the column.
size
size?: numbersize?: numberThe desired size for the column
minSize
minSize?: numberminSize?: numberThe minimum allowed size for the column
maxSize
maxSize?: numbermaxSize?: numberThe maximum allowed size for the column
Column API
Table Options
getSize
getSize: () => numbergetSize: () => numberReturns the current size of the column
getStart
getStart: (position?: ColumnPinningPosition) => numbergetStart: (position?: ColumnPinningPosition) => numberReturns the offset measurement along the row-axis (usually the x-axis for standard tables) for the column.
getCanResize
getCanResize: () => booleangetCanResize: () => booleanReturns true if the column can be resized.
getIsResizing
getIsResizing: () => booleangetIsResizing: () => booleanReturns true if the column is currently being resized.
resetSize
resetSize: () => voidresetSize: () => voidResets the column size to its initial size.
Header API
getSize
getSize: () => numbergetSize: () => numberReturns the size for the header, calculated by summing the size of all leaf-columns that belong to it.
getStart
getStart: (position?: ColumnPinningPosition) => numbergetStart: (position?: ColumnPinningPosition) => numberReturns the offset measurement along the row-axis (usually the x-axis for standard tables) for the header. This is effectively a sum of the offset measurements of all preceding headers.
getResizeHandler
getResizeHandler: () => (event: unknown) => voidgetResizeHandler: () => (event: unknown) => voidReturns an event handler function that can be used to resize the header. It can be used as an:
onMouseDownhandleronTouchStarthandler
The dragging and release events are automatically handled for you.
Table API Options
enableColumnResizing
enableColumnResizing?: booleanenableColumnResizing?: booleanEnables/disables column resizing for *all columns**.
columnResizeMode
columnResizeMode?: 'onChange' | 'onEnd'columnResizeMode?: 'onChange' | 'onEnd'Determines when the columnSizing state is updated. onChange updates the state when the user is dragging the resize handle. onEnd updates the state when the user releases the resize handle.
onColumnSizingChange
onColumnSizingChange?: OnChangeFn<ColumnSizingState>onColumnSizingChange?: OnChangeFn<ColumnSizingState>This optional function will be called when the columnSizing state changes. If you provide this function, you will be responsible for maintaining its state yourself. You can pass this state back to the table via the state.columnSizing table option.
onColumnSizingInfoChange
onColumnSizingInfoChange?: OnChangeFn<ColumnSizingInfoState>onColumnSizingInfoChange?: OnChangeFn<ColumnSizingInfoState>This optional function will be called when the columnSizingInfo state changes. If you provide this function, you will be responsible for maintaining its state yourself. You can pass this state back to the table via the state.columnSizingInfo table option.
Table API
setColumnSizing
setColumnSizing: (updater: Updater<ColumnSizingState>) => voidsetColumnSizing: (updater: Updater<ColumnSizingState>) => voidSets the column sizing state using an updater function or a value. This will trigger the underlying onColumnSizingChange function if one is passed to the table options, otherwise the state will be managed automatically by the table.
setColumnSizingInfo
setColumnSizingInfo: (updater: Updater<ColumnSizingInfoState>) => voidsetColumnSizingInfo: (updater: Updater<ColumnSizingInfoState>) => voidSets the column sizing info state using an updater function or a value. This will trigger the underlying onColumnSizingInfoChange function if one is passed to the table options, otherwise the state will be managed automatically by the table.
resetColumnSizing
resetColumnSizing: (defaultState?: boolean) => voidresetColumnSizing: (defaultState?: boolean) => voidResets column sizing to its initial state. If defaultState is true, the default state for the table will be used instead of the initialValue provided to the table.
resetHeaderSizeInfo
resetHeaderSizeInfo: (defaultState?: boolean) => voidresetHeaderSizeInfo: (defaultState?: boolean) => voidResets column sizing info to its initial state. If defaultState is true, the default state for the table will be used instead of the initialValue provided to the table.
getTotalSize
getTotalSize: () => numbergetTotalSize: () => numberReturns the total size of the table by calculating the sum of the sizes of all leaf-columns.
getLeftTotalSize
getLeftTotalSize: () => numbergetLeftTotalSize: () => numberIf pinning, returns the total size of the left portion of the table by calculating the sum of the sizes of all left leaf-columns.
getCenterTotalSize
getCenterTotalSize: () => numbergetCenterTotalSize: () => numberIf pinning, returns the total size of the center portion of the table by calculating the sum of the sizes of all unpinned/center leaf-columns.
getRightTotalSize
getRightTotalSize: () => numbergetRightTotalSize: () => numberIf pinning, returns the total size of the right portion of the table by calculating the sum of the sizes of all right leaf-columns.
Credits
- Column Sizing - TanStack Table 
v8Docs