Skip to content

@jsvision/datagrid / clampWidth

Function: clampWidth()

clampWidth(requested, minWidth?, maxWidth?): number

Defined in: datagrid/src/column-model.ts:148

Clamp a requested column width to [minWidth ?? DEFAULT_MIN_WIDTH, maxWidth]. The floor always applies; the cap applies only when maxWidth is set (an interactive resize may exceed the auto-fit default, but never a column's own declared max).

Parameters

requested

number

The requested width in cells.

minWidth?

number

The column's minimum width (defaults to DEFAULT_MIN_WIDTH).

maxWidth?

number

The column's maximum width (uncapped when omitted).

Returns

number

The clamped width.

Example

ts
import { clampWidth } from '@jsvision/datagrid';
clampWidth(1, 4, 20);  // 4  (below min)
clampWidth(99, 4, 20); // 20 (above max)
clampWidth(10);        // 10 (within default floor, no cap)