DataGridGeometry

A generic 1-D geometry index for one axis of a DataGrid. Instantiate once per axis (rows and columns).

Vocabulary is abstracted: size (a height or a width), offset (cumulative start along the axis), extent (total size of the axis). The only axis-specific knowledge is how to read an element's size, injected via sizeOf(element):

  • rows → row => row.height ?? estimate (variable, measured)
  • columns → col => resolveWidth(col.width, default) (known config)

Everything else — cumulative offsets (prefix-sum with incremental rebuildFrom), the indexAtOffset hit-test, the CSS track template, and frozenOffsetAt for leading pinned elements — is identical for both axes.

Backed by a prefix-sum array; rebuildFrom(i) reflows the suffix in O(n) (fine for hundreds–thousands of rows). Sizes are cached on rebuild so sizeOf (which may parse a px string) isn't re-run on every read.

DataGrid builds one instance per axis (rowGeometry / columnGeometry).

Example

const rowGeometry = new DataGridGeometry(rows, {
    sizeOf: row => row.height == null ? rowEstimate : row.height
})
const columnGeometry = new DataGridGeometry(columns, {
    sizeOf: col => resolveWidth(col.width, defaultColumnWidth)
})
columnGeometry.template()            // -> "80px 120px 60px"
rowGeometry.indexAtOffset(scrollTop) // -> first visible row index

Constructor

new DataGridGeometry()

Instance Properties

Total size (px) along the axis.

Instance Methods

Sticky offset (px) for a leading frozen element (cumulative size of the frozen elements before it), or null if this element isn't frozen. Elements opt in with a truthy frozen flag; axes without frozen elements always get null.

Largest element index whose start offset is <= offset (the windowing hit-test). Binary search over the prefix-sum array; clamps into [0, n-1].

Cumulative start offset (px) of element i.

Recompute cached sizes + cumulative offsets from index from to the end. Call whenever an element's size changes, or elements are inserted/removed/reordered at/after from. Offsets before from are unaffected, so re-summing only the suffix is sufficient.

Size (px) of element i (cached).

CSS track list of the sizes along this axis (e.g. for grid-template-columns).

Classes