@kanunilabs/datagrid-react / ColumnModel
Class: ColumnModel<TRow>
Type Parameters
TRow
TRow = GridRowData
Constructors
Constructor
new ColumnModel<
TRow>(columns,options?):ColumnModel<TRow>
Parameters
columns
GridColumnDef<TRow>[]
options?
ColumnModelOptions<TRow>
Returns
ColumnModel<TRow>
Methods
applyColumnStates()
applyColumnStates(
states):void
Apply a persisted ColumnState[] (e.g. restored layout). Unknown ids ignored.
Parameters
states
Returns
void
getAuthoredHeaderName()
getAuthoredHeaderName(
id):string|undefined
The name the definition gives, whatever the user renamed it to.
Parameters
id
string
Returns
string | undefined
getCellValue()
getCellValue(
row,id):unknown
Parameters
row
TRow
id
string
Returns
unknown
getCollapsedBands()
getCollapsedBands():
string[]
Every collapsed path, for persistence.
Returns
string[]
getColumnStates()
getColumnStates():
ColumnState[]
Snapshot of every column's live state, in canonical order.
Returns
getDataType()
getDataType(
id):GridDataType
Parameters
id
string
Returns
getDef()
getDef(
id):GridColumnDef<TRow> |undefined
Parameters
id
string
Returns
GridColumnDef<TRow> | undefined
getDefinitionOrder()
getDefinitionOrder():
string[]
Column ids in DEFINITION order — what a stored A1 counts columns in.
Returns
string[]
getEditorDataType()
getEditorDataType(
id):GridDataType
Parameters
id
string
Returns
getFormulaError()
getFormulaError(
id):FormulaCompileError|null
Why a calculated column shows #NAME? — null when its formula compiled.
Parameters
id
string
Returns
FormulaCompileError | null
getNumberFormat()
getNumberFormat(
id):ColumnNumberFormat&object|undefined
A column's numberFormat with its locale resolved, or undefined.
Parameters
id
string
Returns
ColumnNumberFormat & object | undefined
getNumberLocale()
getNumberLocale():
string
The number locale of the grid ('tr' → 'tr-TR'), for number editors without a numberFormat.
Returns
string
getOrder()
getOrder():
string[]
All column ids in canonical order.
Returns
string[]
getSearchFold()
getSearchFold():
LookupMatchFold
How the quick search folds text (searchFold); 'case' when unset.
Returns
LookupMatchFold
getSortValue()
getSortValue(
row,id):unknown
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
Parameters
id
string
Returns
ColumnState | undefined
getStoredValue()
getStoredValue(
row,id):unknown
What the data holds for a cell: the formula TEXT of a formula cell, the
value otherwise. The editor opens on this; the grid shows getCellValue.
Parameters
row
TRow
id
string
Returns
unknown
getVersion()
getVersion():
number
Returns
number
hasCellFormulas()
hasCellFormulas():
boolean
Whether any column takes cell formulas.
Returns
boolean
isBandCollapsed()
isBandCollapsed(
path):boolean
Parameters
path
readonly string[]
Returns
boolean
isBandCollapsible()
isBandCollapsible(
path):boolean
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
isFlexing()
isFlexing(
id):boolean
True while the column takes a share of the spare width.
Parameters
id
string
Returns
boolean
isShown()
isShown(
id):boolean
Visible to the user AND not hidden by the screen's width — what a card shows.
Parameters
id
string
Returns
boolean
moveColumn()
moveColumn(
id,beforeId?):void
Move a column so it sits immediately before beforeId (or last if omitted).
Parameters
id
string
beforeId?
string
Returns
void
parseCellValue()
parseCellValue(
row,id,value,oldValue):unknown
The column's valueParser over typed or pasted input; the input itself
when the column has none.
Parameters
row
TRow
id
string
value
unknown
oldValue
unknown
Returns
unknown
resetColumnStates()
resetColumnStates():
void
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
resolveColumnName()
resolveColumnName(
name):string|null
The column a formula's [Name] means: an id, else a header, case-insensitively.
Parameters
name
string
Returns
string | null
runtime()
runtime(
options?):ColumnRuntime<TRow>[]
Ordered runtime columns for rendering: pinned-left first, then unpinned, then pinned-right — each group in canonical order. Hidden columns dropped.
Parameters
options?
includeScreenHidden?
boolean
Returns
ColumnRuntime<TRow>[]
setBandCollapsed()
setBandCollapsed(
path,collapsed):boolean
Returns true when the state actually moved, so callers can skip a no-op.
Parameters
path
readonly string[]
collapsed
boolean
Returns
boolean
setCellFormulaReader()
setCellFormulaReader(
reader):void
Parameters
reader
((row, columnId, text) => unknown) | null
Returns
void
setCellValue()
setCellValue(
row,id,value):boolean
Write an edited value into a row: the column's valueSetter when it has
one, else the column's field (its id when it has none). False when the
setter said nothing changed.
The ONE write of an edit, for both renderers. The editing layers each did
row[columnId] = value themselves, which wrote a column defined as
{ id: 'n', field: 'name' } into a stray row.n the grid never reads —
and two copies of the rule are two places for the next one to diverge.
Parameters
row
TRow
id
string
value
unknown
Returns
boolean
setCollapsedBands()
setCollapsedBands(
keys):void
Restore from getCollapsedBands().
Parameters
keys
readonly string[]
Returns
void
setColumns()
setColumns(
columns):void
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
setFlex()
setFlex(
id,flex):void
Set a flex column's share; 0 fixes it at its current width. No-op on a column defined without flex.
Parameters
id
string
flex
number
Returns
void
setGridWidth()
setGridWidth(
width):boolean
The grid's measured width. True when it moved a column across its hideBelow.
Parameters
width
number
Returns
boolean
setHeaderName()
setHeaderName(
id,name):boolean
Rename a column in the grid (G-CORE-06). An empty name, or the authored one, goes back to the definition. True when the shown name changed.
Parameters
id
string
name
string | null | undefined
Returns
boolean
setPinned()
setPinned(
id,pinned):void
Parameters
id
string
pinned
Returns
void
setSearchFold()
setSearchFold(
fold):void
Parameters
fold
LookupMatchFold | undefined
Returns
void
setVisible()
setVisible(
id,visible):void
Parameters
id
string
visible
boolean
Returns
void
setWidth()
setWidth(
id,width):void
Parameters
id
string
width
number
Returns
void