Documentation

@kanunilabs/datagrid-react


@kanunilabs/datagrid-react / ColumnModel

Class: ColumnModel<TRow>

Defined in: datagrid-core/dist/index.d.ts:1262

Type Parameters

TRow

TRow = GridRowData

Constructors

Constructor

new ColumnModel<TRow>(columns, options?): ColumnModel<TRow>

Defined in: datagrid-core/dist/index.d.ts:1279

Parameters

columns

GridColumnDef<TRow>[]

options?

ColumnModelOptions<TRow>

Returns

ColumnModel<TRow>

Methods

applyColumnStates()

applyColumnStates(states): void

Defined in: datagrid-core/dist/index.d.ts:1342

Apply a persisted ColumnState[] (e.g. restored layout). Unknown ids ignored.

Parameters

states

ColumnState[]

Returns

void


getCellValue()

getCellValue(row, id): unknown

Defined in: datagrid-core/dist/index.d.ts:1343

Parameters

row

TRow

id

string

Returns

unknown


getCollapsedBands()

getCollapsedBands(): string[]

Defined in: datagrid-core/dist/index.d.ts:1324

Every collapsed path, for persistence.

Returns

string[]


getColumnStates()

getColumnStates(): ColumnState[]

Defined in: datagrid-core/dist/index.d.ts:1314

Snapshot of every column's live state, in canonical order.

Returns

ColumnState[]


getDataType()

getDataType(id): GridDataType

Defined in: datagrid-core/dist/index.d.ts:1351

Parameters

id

string

Returns

GridDataType


getDef()

getDef(id): GridColumnDef<TRow> | undefined

Defined in: datagrid-core/dist/index.d.ts:1309

Parameters

id

string

Returns

GridColumnDef<TRow> | undefined


getOrder()

getOrder(): string[]

Defined in: datagrid-core/dist/index.d.ts:1312

All column ids in canonical order.

Returns

string[]


getSortValue()

getSortValue(row, id): unknown

Defined in: datagrid-core/dist/index.d.ts:1350

Value used for ordering — honors calculateSortValue, else the cell value.

Resolves the definition ONCE. Delegating to getCellValue looked cleaner but looked the column up a second time, and this runs per row per sort key.

Parameters

row

TRow

id

string

Returns

unknown


getState()

getState(id): ColumnState | undefined

Defined in: datagrid-core/dist/index.d.ts:1310

Parameters

id

string

Returns

ColumnState | undefined


getVersion()

getVersion(): number

Defined in: datagrid-core/dist/index.d.ts:1280

Returns

number


isBandCollapsed()

isBandCollapsed(path): boolean

Defined in: datagrid-core/dist/index.d.ts:1320

Parameters

path

readonly string[]

Returns

boolean


isBandCollapsible()

isBandCollapsible(path): boolean

Defined in: datagrid-core/dist/index.d.ts:1335

Can this band be folded at all?

TWO conditions, and the second is the one that is easy to miss: the band needs something to HIDE (a 'open' column) and something to LEAVE BEHIND. A band whose every column disappears on collapse takes its own header cell with it — and with it the toggle, so the user could never open it again.

Parameters

path

readonly string[]

Returns

boolean


moveColumn()

moveColumn(id, beforeId?): void

Defined in: datagrid-core/dist/index.d.ts:1340

Move a column so it sits immediately before beforeId (or last if omitted).

Parameters

id

string

beforeId?

string

Returns

void


resetColumnStates()

resetColumnStates(): void

Defined in: datagrid-core/dist/index.d.ts:1308

Discard every runtime change and return to what the definitions say.

NOT setColumns(this.defs) — that path deliberately PRESERVES the user's runtime state (its authorship rule exists so a re-render doesn't wipe the layout). Reset is the one caller whose whole point is to wipe it: width, pin, visibility and order all come back from the defs, order from the authored sequence.

Returns

void


runtime()

runtime(): ColumnRuntime<TRow>[]

Defined in: datagrid-core/dist/index.d.ts:1319

Ordered runtime columns for rendering: pinned-left first, then unpinned, then pinned-right — each group in canonical order. Hidden columns dropped.

Returns

ColumnRuntime<TRow>[]


setBandCollapsed()

setBandCollapsed(path, collapsed): boolean

Defined in: datagrid-core/dist/index.d.ts:1322

Returns true when the state actually moved, so callers can skip a no-op.

Parameters

path

readonly string[]

collapsed

boolean

Returns

boolean


setCollapsedBands()

setCollapsedBands(keys): void

Defined in: datagrid-core/dist/index.d.ts:1326

Restore from getCollapsedBands().

Parameters

keys

readonly string[]

Returns

void


setColumns()

setColumns(columns): void

Defined in: datagrid-core/dist/index.d.ts:1298

Replace the column set, KEEPING what the user changed at runtime.

This used to preserve nothing, and the adapter calls it whenever the columns prop changes IDENTITY — which for an app that writes columns={[...]} inline is every single render. Pinning a column, widening it, hiding it or dragging it somewhere else all lasted until the next re-render and then silently snapped back to the definitions. The symptom that found it: unfix three columns, click anywhere, and all three are pinned again.

The rule is authorship. A property the AUTHOR changed in the definition wins — they have said something new. A property the author left alone keeps whatever the USER did to it. Comparing against the PREVIOUS definition is what separates the two; comparing against the live state cannot, because a user-pinned column and an author-pinned one look identical.

Parameters

columns

GridColumnDef<TRow>[]

Returns

void


setPinned()

setPinned(id, pinned): void

Defined in: datagrid-core/dist/index.d.ts:1337

Parameters

id

string

pinned

ColumnPin

Returns

void


setVisible()

setVisible(id, visible): void

Defined in: datagrid-core/dist/index.d.ts:1338

Parameters

id

string

visible

boolean

Returns

void


setWidth()

setWidth(id, width): void

Defined in: datagrid-core/dist/index.d.ts:1336

Parameters

id

string

width

number

Returns

void