View as Markdown

API reference: @salmonui/data-grid/engine

EditApiinterface

import type { EditApi } from '@salmonui/data-grid/engine';

Also exported from @salmonui/data-grid/engine/edit.

interface EditApi<Row> {
    startEdit(rowId?: RowId, field?: string): CommandResult;
    save(): CommandResult;
    saveCell(): CommandResult;
    cancelEdit(): CommandResult;
    setEditValue(rowId: RowId, field: string, value: unknown): CommandResult;
    addRow(row?: Readonly<Record<string, unknown>>, index?: number): CommandResult;
    deleteRows(rowIds?: RowId | readonly RowId[]): CommandResult;
    updateRow(rowId: RowId, row: Readonly<Record<string, unknown>>): CommandResult;
    updateCell(rowId: RowId, field: string, value: unknown): CommandResult;
    setCellValue(rowId: RowId, field: string, value: unknown): CommandResult;
    setRowData(rowId: RowId, row: Row): CommandResult;
    applyChanges(changes: EditDataChanges<Row>): CommandResult;
    getPendingChanges(): EditBatchChanges<Row>;
    getBatchPreview(): EditPreview | undefined;
    getEditSnapshot(): EditSnapshot | undefined;
    hasUnsavedChanges(): boolean;
    whenEditSettled(): Promise<void>;
    validateBatch(): Promise<boolean>;
    undo(): CommandResult;
    redo(): CommandResult;
    canUndo(): boolean;
    canRedo(): boolean;
}

Edit methods. Columns are named by field or column id (the column id wins); value maps (addRow, updateRow) are keyed the same way.

EditApi members (22)
NameSignatureDescription
startEditstartEdit(rowId?: RowId, field?: string): CommandResult;

Row and dialog mode edit the row, batch and cell mode the cell (default: first editable). Without a row id, the first selected row.

savesave(): CommandResult;

Saves the edit: commits the active row or cell; in batch mode saves every pending change.

saveCellsaveCell(): CommandResult;

Commits the active editor only: the row in row and dialog mode, the cell in batch and cell mode (batch mode keeps the change pending).

cancelEditcancelEdit(): CommandResult;

Discards the active editor; in batch mode without an open editor, every pending change.

setEditValuesetEditValue(rowId: RowId, field: string, value: unknown): CommandResult;

Sets the draft of the active editor (or of any editable cell).

addRowaddRow(row?: Readonly<Record<string, unknown>>, index?: number): CommandResult;

Adds a row (and edits it). index 0 adds at the top, an index at or past the end at the bottom; other positions are rejected (unsupportedIndex). Without an index the row goes to newRowPosition.

deleteRowsdeleteRows(rowIds?: RowId | readonly RowId[]): CommandResult;

Batch mode marks the rows; other modes write at once. Without ids, the selected rows.

updateRowupdateRow(rowId: RowId, row: Readonly<Record<string, unknown>>): CommandResult;

Validates and writes the values.

updateCellupdateCell(rowId: RowId, field: string, value: unknown): CommandResult;

Edits a cell as a user would: batch mode keeps a draft; other modes write at once.

setCellValuesetCellValue(rowId: RowId, field: string, value: unknown): CommandResult;

Silent data update of one cell (no edit lifecycle or validation). Local data sources only.

setRowDatasetRowData(rowId: RowId, row: Row): CommandResult;

Silent replacement of a row (no edit lifecycle or validation). Local data sources only.

applyChangesapplyChanges(changes: EditDataChanges<Row>): CommandResult;

Silent bulk data update (no edit lifecycle or validation). Local data sources only.

getPendingChangesgetPendingChanges(): EditBatchChanges<Row>;

Added, changed, and deleted rows not saved yet.

getBatchPreviewgetBatchPreview(): EditPreview | undefined;
getEditSnapshotgetEditSnapshot(): EditSnapshot | undefined;
hasUnsavedChangeshasUnsavedChanges(): boolean;
whenEditSettledwhenEditSettled(): Promise<void>;

Resolves when pending writes and async validators settled.

validateBatchvalidateBatch(): Promise<boolean>;

Validates every pending change without saving and publishes the errors; resolves true when everything is valid once async validators settled.

undoundo(): CommandResult;

Reverts the last edit action (needs undo: true).

redoredo(): CommandResult;

Re-applies the last undone action.

canUndocanUndo(): boolean;
canRedocanRedo(): boolean;