# EditApi (@salmonui/data-grid/engine)

> The EditApi interface of @salmonui/data-grid/engine: Edit methods. Columns are named by field or column id (the column id wins); value maps (addRow, updateRow) are keyed the same way.

Canonical: https://salmonui.dev/docs/reference/data-grid/engine/EditApi

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

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

Entry index: https://salmonui.dev/docs/reference/data-grid/engine (Markdown with every symbol of the entry: https://salmonui.dev/docs/reference/data-grid/engine.md).

## Reference

Kind: interface

```ts
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.

Members (22):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `startEdit` | `startEdit(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. |
| `save` | `save(): CommandResult;` |  | Saves the edit: commits the active row or cell; in batch mode saves every pending change. |
| `saveCell` | `saveCell(): 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). |
| `cancelEdit` | `cancelEdit(): CommandResult;` |  | Discards the active editor; in batch mode without an open editor, every pending change. |
| `setEditValue` | `setEditValue(rowId: RowId, field: string, value: unknown): CommandResult;` |  | Sets the draft of the active editor (or of any editable cell). |
| `addRow` | `addRow(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`. |
| `deleteRows` | `deleteRows(rowIds?: RowId \| readonly RowId[]): CommandResult;` |  | Batch mode marks the rows; other modes write at once. Without ids, the selected rows. |
| `updateRow` | `updateRow(rowId: RowId, row: Readonly<Record<string, unknown>>): CommandResult;` |  | Validates and writes the values. |
| `updateCell` | `updateCell(rowId: RowId, field: string, value: unknown): CommandResult;` |  | Edits a cell as a user would: batch mode keeps a draft; other modes write at once. |
| `setCellValue` | `setCellValue(rowId: RowId, field: string, value: unknown): CommandResult;` |  | Silent data update of one cell (no edit lifecycle or validation). Local data sources only. |
| `setRowData` | `setRowData(rowId: RowId, row: Row): CommandResult;` |  | Silent replacement of a row (no edit lifecycle or validation). Local data sources only. |
| `applyChanges` | `applyChanges(changes: EditDataChanges<Row>): CommandResult;` |  | Silent bulk data update (no edit lifecycle or validation). Local data sources only. |
| `getPendingChanges` | `getPendingChanges(): EditBatchChanges<Row>;` |  | Added, changed, and deleted rows not saved yet. |
| `getBatchPreview` | `getBatchPreview(): EditPreview \| undefined;` |  |  |
| `getEditSnapshot` | `getEditSnapshot(): EditSnapshot \| undefined;` |  |  |
| `hasUnsavedChanges` | `hasUnsavedChanges(): boolean;` |  |  |
| `whenEditSettled` | `whenEditSettled(): Promise<void>;` |  | Resolves when pending writes and async validators settled. |
| `validateBatch` | `validateBatch(): Promise<boolean>;` |  | Validates every pending change without saving and publishes the errors; resolves true when everything is valid once async validators settled. |
| `undo` | `undo(): CommandResult;` |  | Reverts the last edit action (needs `undo: true`). |
| `redo` | `redo(): CommandResult;` |  | Re-applies the last undone action. |
| `canUndo` | `canUndo(): boolean;` |  |  |
| `canRedo` | `canRedo(): boolean;` |  |  |
