Skip to main content

Interface: Table<Row>

Defined in: packages/sdvtables/src/engine.ts:90

The headless table engine: holds the rows and a TableState, derives the visible page, and notifies subscribers. Renderers (static HTML, hydrate, React) read rows/columns and call the setters; nothing here touches the DOM.

Example​

A hover set before any view attaches: the view lights it when it does (getHover)

import { createTable, defineTable } from "@sportsdataverse/sdvtables";
import { hydrate, renderHTML } from "@sportsdataverse/sdvtables/html";

// 2024 AFC: Kansas City 15 wins, Buffalo 13
const spec = defineTable<{ team: string; wins: number }>()
.columns((c) => [c.text("team"), c.int("wins")])
.rowKey("team")
.build();
const table = createTable(spec, [
{ team: "KC", wins: 15 },
{ team: "BUF", wins: 13 },
]);
table.setHover("BUF"); // a linked figure's hover, before the table is on the page
table.getHover(); // "BUF"
const root = document.createElement("div");
root.innerHTML = renderHTML(table, { fonts: false });
hydrate(root, table); // Buffalo's row gets sdvt-hover as it attaches
root;

Type Parameters​

Row​

Row

Properties​

allRows​

readonly allRows: readonly Row[]

Defined in: packages/sdvtables/src/engine.ts:93

the source rows: the ones given to createTable, or the last setRows


columns​

readonly columns: readonly ColumnSpec<Row>[]

Defined in: packages/sdvtables/src/engine.ts:99

visible columns in spec order


filteredCount​

readonly filteredCount: number

Defined in: packages/sdvtables/src/engine.ts:96


pageCount​

readonly pageCount: number

Defined in: packages/sdvtables/src/engine.ts:97


rows​

readonly rows: readonly Row[]

Defined in: packages/sdvtables/src/engine.ts:95


spec​

readonly spec: TableSpec<Row>

Defined in: packages/sdvtables/src/engine.ts:91


state​

readonly state: TableState<Row>

Defined in: packages/sdvtables/src/engine.ts:94

Methods​

getHover()​

getHover(): string | null

Defined in: packages/sdvtables/src/engine.ts:125

J31: the last setHover id, or null. A view that attaches (hydrate) or mounts (<SdvTable table/>) after a hover reads it, since no event comes until the hover changes.

Returns​

string | null


getSelection()​

getSelection(): ReadonlySet<string>

Defined in: packages/sdvtables/src/engine.ts:118

Returns​

ReadonlySet<string>


getSnapshot()​

getSnapshot(): TableSnapshot<Row>

Defined in: packages/sdvtables/src/engine.ts:133

referentially stable until the next mutation — what useSyncExternalStore reads

Returns​

TableSnapshot<Row>


rowId()​

rowId(row): string

Defined in: packages/sdvtables/src/engine.ts:113

J31: String(row[spec.rowKey]) ("" when missing), else the row's index in allRows

Parameters​

row​

Row

Returns​

string


setCursor()​

setCursor(row, col): void

Defined in: packages/sdvtables/src/engine.ts:130

Task 10: move the keyboard cursor. row is clamped to the current page; col must name a spec column, or be null. One "change" event; an equal cursor (after clamping) is a no-op, and a non-finite row is ignored.

Parameters​

row​

number

col​

string | null

Returns​

void


setExternalFilter()​

setExternalFilter(filter): void

Defined in: packages/sdvtables/src/engine.ts:115

J31: same function again is a no-op; a new one resets the page

Parameters​

filter​

RowFilter<Row> | null

Returns​

void


setFilter()​

setFilter(col, filter): void

Defined in: packages/sdvtables/src/engine.ts:101

Parameters​

col​

string

filter​

FilterValue<Row> | null | undefined

Returns​

void


setGlobalFilter()​

setGlobalFilter(text): void

Defined in: packages/sdvtables/src/engine.ts:102

Parameters​

text​

string

Returns​

void


setHover()​

setHover(id): void

Defined in: packages/sdvtables/src/engine.ts:120

J31: emits { type: "hover" } without changing state; the same id twice in a row is a no-op

Parameters​

id​

string | null

Returns​

void


setPage()​

setPage(n): void

Defined in: packages/sdvtables/src/engine.ts:103

Parameters​

n​

number

Returns​

void


setPageSize()​

setPageSize(n): void

Defined in: packages/sdvtables/src/engine.ts:104

Parameters​

n​

number

Returns​

void


setRows()​

setRows(rows): void

Defined in: packages/sdvtables/src/engine.ts:111

Replace the source rows (a React parent's new array, a live feed). Sort, filters, the external filter, hidden columns and selection are kept; the page is clamped to the new page count; one "change" event. Without a rowKey, row ids are indices into the NEW rows, so a kept selection means the rows at those positions.

Parameters​

rows​

readonly Row[]

Returns​

void


setSelection()​

setSelection(ids): void

Defined in: packages/sdvtables/src/engine.ts:117

J31: emits { type: "select" }; an equal set is a no-op

Parameters​

ids​

ReadonlySet<string>

Returns​

void


setSort()​

setSort(col, dir): void

Defined in: packages/sdvtables/src/engine.ts:100

Parameters​

col​

string

dir​

SortDir | null

Returns​

void


subscribe()​

subscribe(fn): () => void

Defined in: packages/sdvtables/src/engine.ts:131

Parameters​

fn​

(event) => void

Returns​

() => void


toggleColumn()​

toggleColumn(col, visible?): void

Defined in: packages/sdvtables/src/engine.ts:105

Parameters​

col​

string

visible?​

boolean

Returns​

void