View as Markdown

API reference: @salmonui/data-grid

DataGridEditApiinterface

import type { DataGridEditApi } from '@salmonui/data-grid';
interface DataGridEditApi<Row> extends DataGridClipboardApi {
    startEdit(rowId?: RowId, field?: string): CommandResult;
    save(): CommandResult;
    saveCell(): CommandResult;
    cancelEdit(): 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;
    fillSelection(rowId: RowId, field: string): CommandResult;
}

Editing methods of the DataGrid instance.

DataGridEditApi members (22, 2 inherited)
NameSignatureDescription
startEditstartEdit(rowId?: RowId, field?: string): CommandResult;

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

savesave(): CommandResult;

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

saveCellsaveCell(): CommandResult;

Commits the active editor only (batch mode keeps the change pending).

cancelEditcancelEdit(): CommandResult;

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

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

Index 0 adds at the top, at or past the end at the bottom.

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

Without ids: the selected rows. Batch mode marks the rows until save.

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

Edits a cell as a user would (draft in batch mode).

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

Silent data updates without the edit lifecycle (local sources).

setRowDatasetRowData(rowId: RowId, row: Row): CommandResult;
applyChangesapplyChanges(changes: EditDataChanges<Row>): CommandResult;
getPendingChangesgetPendingChanges(): EditBatchChanges<Row>;
getBatchPreviewgetBatchPreview(): EditPreview | undefined;
getEditSnapshotgetEditSnapshot(): EditSnapshot | undefined;
hasUnsavedChangeshasUnsavedChanges(): boolean;
whenEditSettledwhenEditSettled(): Promise<void>;
validateBatchvalidateBatch(): Promise<boolean>;

Validates every pending change without saving; resolves true when valid.

undoundo(): CommandResult;

Undoes the last edit (needs editing.undo).

redoredo(): CommandResult;
fillSelectionfillSelection(rowId: RowId, field: string): CommandResult;

Fills the selected cell range's content over the range extended to field of rowId (fill handle).

copyinheritedcopy: (options?: DataGridCopyOptions | undefined) => CommandResult;

Copies the cell range, else the selected rows, else the focused cell to the system clipboard (drafts included). Falls back to a copy dialog when the browser blocks clipboard access. rejected with nothingToCopy or cancelled (onBeforeCopy).

pasteinheritedpaste: (text?: string | undefined) => CommandResult;

Pastes TSV text at the selected range or focused cell. Without text, reads the system clipboard (async), or opens a paste dialog when the Clipboard API is unavailable.