Skip to content

@jsvision/ui / measureAutoWidths

Function: measureAutoWidths()

measureAutoWidths<T>(columns, rows, measure): (number | null)[]

Defined in: ui/src/table/columns.ts:76

Pre-measure auto columns to a fixed cell width across ALL current rows. This is the O(rows) pass; wrap it in a computed over the rows signal so it re-runs only when the data changes, not every frame.

Per column: null for number/fr columns; for auto, the widest cell across all rows, floored to the header title width (never 0 — an empty grid falls back to the title) and to minWidth, then capped by maxWidth (if minWidth > maxWidth, maxWidth wins).

Type Parameters

T

T

Parameters

columns

Column<T>[]

The column descriptors.

rows

T[]

The current (unsorted) row snapshot.

measure

(s) => number

Display-width function (measures each string in terminal cells, wide-glyph aware).

Returns

(number | null)[]

One entry per column: the measured auto width, or null for non-auto columns.

Example

ts
import { measureAutoWidths } from '@jsvision/ui';
import type { Column } from '@jsvision/ui';

interface Person {
  name: string;
}

const cols: Column<Person>[] = [{ title: 'Name', accessor: (r) => r.name, width: 'auto' as const }];
measureAutoWidths(cols, [{ name: 'Ada' }, { name: 'Bartholomew' }], (s) => s.length); // [11]