Framework
Version
Menu
Getting Started
Core Guides
Feature Guides
Core APIs
Feature APIs
Enterprise
Examples

Column Sizing APIs

State

Column sizing state is stored on the table using the following shape:

tsx
tsx
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][]
}
tsx
tsx
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

tsx
tsx
enableResizing?: boolean
tsx
tsx
enableResizing?: boolean

Enables or disables column resizing for the column.

size

tsx
tsx
size?: number
tsx
tsx
size?: number

The desired size for the column

minSize

tsx
tsx
minSize?: number
tsx
tsx
minSize?: number

The minimum allowed size for the column

maxSize

tsx
tsx
maxSize?: number
tsx
tsx
maxSize?: number

The maximum allowed size for the column

Column API

getSize

tsx
tsx
getSize: () => number
tsx
tsx
getSize: () => number

Returns the current size of the column

getStart

tsx
tsx
getStart: (position?: ColumnPinningPosition) => number
tsx
tsx
getStart: (position?: ColumnPinningPosition) => number

Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the column, measuring the size of all preceding columns.

Useful for sticky or absolute positioning of columns. (e.g. left or transform)

getAfter

tsx
tsx
getAfter: (position?: ColumnPinningPosition) => number
tsx
tsx
getAfter: (position?: ColumnPinningPosition) => number

Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the column, measuring the size of all succeeding columns.

Useful for sticky or absolute positioning of columns. (e.g. right or transform)

getCanResize

tsx
tsx
getCanResize: () => boolean
tsx
tsx
getCanResize: () => boolean

Returns true if the column can be resized.

getIsResizing

tsx
tsx
getIsResizing: () => boolean
tsx
tsx
getIsResizing: () => boolean

Returns true if the column is currently being resized.

resetSize

tsx
tsx
resetSize: () => void
tsx
tsx
resetSize: () => void

Resets the column size to its initial size.

Header API

getSize

tsx
tsx
getSize: () => number
tsx
tsx
getSize: () => number

Returns the size for the header, calculated by summing the size of all leaf-columns that belong to it.

getStart

tsx
tsx
getStart: (position?: ColumnPinningPosition) => number
tsx
tsx
getStart: (position?: ColumnPinningPosition) => number

Returns 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

tsx
tsx
getResizeHandler: () => (event: unknown) => void
tsx
tsx
getResizeHandler: () => (event: unknown) => void

Returns an event handler function that can be used to resize the header. It can be used as an:

  • onMouseDown handler
  • onTouchStart handler

The dragging and release events are automatically handled for you.

Table Options

enableColumnResizing

tsx
tsx
enableColumnResizing?: boolean
tsx
tsx
enableColumnResizing?: boolean

Enables/disables column resizing for *all columns**.

columnResizeMode

tsx
tsx
columnResizeMode?: 'onChange' | 'onEnd'
tsx
tsx
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.

columnResizeDirection

tsx
tsx
columnResizeDirection?: 'ltr' | 'rtl'
tsx
tsx
columnResizeDirection?: 'ltr' | 'rtl'

Enables or disables right-to-left support for resizing the column. defaults to 'ltr'.

onColumnSizingChange

tsx
tsx
onColumnSizingChange?: OnChangeFn<ColumnSizingState>
tsx
tsx
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

tsx
tsx
onColumnSizingInfoChange?: OnChangeFn<ColumnSizingInfoState>
tsx
tsx
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

tsx
tsx
setColumnSizing: (updater: Updater<ColumnSizingState>) => void
tsx
tsx
setColumnSizing: (updater: Updater<ColumnSizingState>) => void

Sets 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

tsx
tsx
setColumnSizingInfo: (updater: Updater<ColumnSizingInfoState>) => void
tsx
tsx
setColumnSizingInfo: (updater: Updater<ColumnSizingInfoState>) => void

Sets 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

tsx
tsx
resetColumnSizing: (defaultState?: boolean) => void
tsx
tsx
resetColumnSizing: (defaultState?: boolean) => void

Resets 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

tsx
tsx
resetHeaderSizeInfo: (defaultState?: boolean) => void
tsx
tsx
resetHeaderSizeInfo: (defaultState?: boolean) => void

Resets 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

tsx
tsx
getTotalSize: () => number
tsx
tsx
getTotalSize: () => number

Returns the total size of the table by calculating the sum of the sizes of all leaf-columns.

getLeftTotalSize

tsx
tsx
getLeftTotalSize: () => number
tsx
tsx
getLeftTotalSize: () => number

If 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

tsx
tsx
getCenterTotalSize: () => number
tsx
tsx
getCenterTotalSize: () => number

If 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

tsx
tsx
getRightTotalSize: () => number
tsx
tsx
getRightTotalSize: () => number

If pinning, returns the total size of the right portion of the table by calculating the sum of the sizes of all right leaf-columns.

Subscribe to Bytes

Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.

Bytes

No spam. Unsubscribe at any time.