Column Stretch
Column Stretch
Section titled “Column Stretch”When total column width is less than the container width, stretchColumns distributes the remaining space so columns fill the container. Two modes are available: 'all' distributes space evenly across stretchable columns, 'last' gives all extra space to the last visible column.
Configuration
Section titled “Configuration”<Spreadsheet columns={columns} data={data} stretchColumns="all"/>| Value | Behavior |
|---|---|
'all' | Extra space distributed evenly among stretchable columns |
'last' | All extra space added to the last visible column |
undefined | No stretching (default) — columns use their defined widths |
How It Works
Section titled “How It Works”The ColumnStretchManager calculates stretched widths:
- Sum all visible column widths
- If total ≥ container width → no stretch needed (return)
- Calculate
extraSpace = containerWidth - totalColumnWidth - Distribute based on mode
'all' Mode
Section titled “'all' Mode”Extra space is divided equally among stretchable columns. A column is stretchable if it is:
- Not frozen
- Not manually resized by the user
perColumn = extraSpace / stretchableCountnewWidth = Math.max(currentWidth + perColumn, minWidth ?? 30)If all columns are frozen or manually resized, 'all' mode falls back to 'last' mode.
'last' Mode
Section titled “'last' Mode”All extra space goes to the last visible column:
lastColumnWidth = currentWidth + extraSpaceManual Column Resize
Section titled “Manual Column Resize”When a user manually resizes a column:
- The column is marked as
manuallyResized - Stretch recalculates — the resized column keeps its manual width
- Remaining extra space is redistributed among non-manual, non-frozen columns
Manual resize marks are tracked in a Set. Clearing marks (e.g., on column reorder) re-enables stretch for those columns.
Container Resize
Section titled “Container Resize”A ResizeObserver monitors the container element. When the container changes size:
- Canvas dimensions are synced
- Column stretch recalculates with the new container width
- The table re-renders with updated widths
This means stretch responds automatically to browser window resize, sidebar toggles, or any container layout change.
Frozen Column Interaction
Section titled “Frozen Column Interaction”Frozen columns are never stretched — their widths are fixed. However, their widths count toward the total, reducing the available space for stretched columns.
Available stretch space = containerWidth - totalVisibleColumnWidthsMinimum Column Width
Section titled “Minimum Column Width”Each column respects ColumnDef.minWidth (default: 30px). Stretch never shrinks a column below its minimum. If the perColumn addition would result in a width below minWidth, the minimum is enforced.
When Stretch Has No Effect
Section titled “When Stretch Has No Effect”Stretch does nothing when:
- Total column width already equals or exceeds container width
stretchColumnsis not set- Container width is unknown (not yet mounted)
See Also
Section titled “See Also”- Column & Row Resize — manual column resizing
- Frozen Panes — frozen columns are excluded from stretch
- Text Wrapping — stretched columns affect available wrap width