Documentation

@kanunilabs/datagrid-react


@kanunilabs/datagrid-react / EditingApi

Interface: EditingApi<TRow>

What an app can do with a mounted grid's editing (P-1). Reach it through editing.onReady(api) or controller.editing; both hand out the SAME object for the grid's whole mounted life.

While the grid is not mounted (before mount, after unmount, or with editing switched off) no method throws: the queries answer "nothing" (false, [], null, undefined), the actions do nothing and report it (addRow → null, removeRow/undo/revertRow… → false), and saveChanges resolves { saved: false, changes: [], error } without calling onSave. isAttached() says which case applies.

Type Parameters

TRow

TRow = GridRowData

Methods

addRow()

addRow(values?, beforeKey?): RowKey | null

Add a row (needs allowAdding). With a field rowKey, a key given in values (or by onInitNewRow) is the row's key; otherwise a temporary one is minted. In the cell modes its first editable cell opens. Null when adding is not allowed.

Parameters

values?

Record<string, unknown>

beforeKey?

RowKey

Returns

RowKey | null


cancelChanges()

cancelChanges(): void

Drop every pending change and the undo history (what the batch Cancel does).

Returns

void


canRedo()

canRedo(): boolean

Returns

boolean


canUndo()

canUndo(): boolean

Returns

boolean


effectiveRow()

effectiveRow(rowKey): TRow | undefined

The row as the user sees it: stored values with the pending edits on top.

Parameters

rowKey

RowKey

Returns

TRow | undefined


getChanges()

getChanges(): RowChange<TRow>[]

The pending changes, one RowChange per row — what onSave would get.

Returns

RowChange<TRow>[]


getErrorRowKeys()

getErrorRowKeys(): RowKey[]

Every row currently showing error.

Returns

RowKey[]


getRowStatus()

getRowStatus(rowKey): RowSaveStatus | null

The row's save status (rowStatus): new, changed, removed, saving, saved, error or null — one answer, by the priority error > saving > removed > new > changed > saved.

Parameters

rowKey

RowKey

Returns

RowSaveStatus | null


getRowStatusError()

getRowStatusError(rowKey): string | null

Why the row's last save was refused, while its status is error.

Parameters

rowKey

RowKey

Returns

string | null


hasChanges()

hasChanges(): boolean

Anything pending (an edit, an added or a removed row)?

Returns

boolean


isAttached()

isAttached(): boolean

True while a mounted grid's editing answers the calls.

Returns

boolean


isDirty()

isDirty(rowKey, columnId?): boolean

Does this row (or this cell) have a pending change?

Parameters

rowKey

RowKey

columnId?

string

Returns

boolean


isRemoved()

isRemoved(rowKey): boolean

Parameters

rowKey

RowKey

Returns

boolean


redo()

redo(): boolean

Returns

boolean


removeRow()

removeRow(rowKey): boolean

Delete a row (needs allowDeleting) WITHOUT asking — the app asked already. A new, unsaved row just leaves; in batch an existing row is marked removed until the save.

Parameters

rowKey

RowKey

Returns

boolean


restoreRow()

restoreRow(rowKey): void

Lift a pending delete (batch).

Parameters

rowKey

RowKey

Returns

void


revertCell()

revertCell(rowKey, columnId): boolean

Drop one cell's pending edit (and the history steps that changed it).

Parameters

rowKey

RowKey

columnId

string

Returns

boolean


revertRow()

revertRow(rowKey): boolean

Put one row back as stored — its edits, its pending delete, or (a new row) the row itself. Other rows keep their changes; only the history steps that change this row are dropped.

Parameters

rowKey

RowKey

Returns

boolean


saveChanges()

saveChanges(rowKey?): Promise<SaveResult<TRow>>

Send the pending changes (all, or only rowKey's). An open cell editor is committed first, so the value being typed is part of the save. Resolves the result; rows lists the refused rows of a SaveRejected.

Parameters

rowKey?

RowKey

Returns

Promise<SaveResult<TRow>>


setRowValues()

setRowValues(rowKey, values): boolean

Write several fields of one row in ONE step (P-4.3) — a picker writing code, name and id together: one undo step, one validation pass, the row turns changed once; batch keeps it pending, cell sends one save carrying every field. All or nothing: a column's editable: false does not stop it (that only stops the user typing), but a row lock (allowUpdating refusing that row/column), a failing rule or a valueSetter refusing any one field writes NONE and answers false. In a row mode the row must be the open one. An editor open on that row stays open and shows the new value.

Parameters

rowKey

RowKey

values

Readonly<Record<string, unknown>>

Returns

boolean


undo()

undo(): boolean

Undo the last edit action. False when nothing was undone (or history is off).

Returns

boolean