Skip to content

@jsvision/datagrid / fromRows

Function: fromRows()

fromRows<T>(rows, opts): GridDataSource<T>

Defined in: datagrid/src/data-source.ts:93

Build an in-memory data source over a reactive rows signal. length/rowAt read the signal, so a container that reads them inside a reactive scope re-runs when rows changes. rowKey is required.

It also implements the insert/remove mutation seam: each splices a new array into the signal (never mutating in place), so every reader re-derives and the grid repaints. The caller owns key generation — insert takes a row that already carries its rowKey.

Type Parameters

T

T

Parameters

rows

Signal<T[]>

A signal holding the display-ordered rows.

opts

Row identity — rowKey maps a row to a stable string/number key (required).

rowKey

(row) => string | number

Returns

GridDataSource<T>

A GridDataSource backed by the signal, with the mutation seam wired.

Example

ts
import { signal } from '@jsvision/ui';
import { fromRows } from '@jsvision/datagrid';
const rows = signal([{ id: 1, name: 'Ada' }, { id: 2, name: 'Bo' }]);
const source = fromRows(rows, { rowKey: (r) => r.id });
source.length();            // 2
source.rowAt(0);            // { id: 1, name: 'Ada' }
source.insert!({ id: 3, name: 'Cy' }); // appended → rows() has 3 entries
source.remove!([1]);        // drops id 1 → rows() is [{ id: 2 }, { id: 3 }]