# DataGridEditApi (@salmonui/data-grid)

> The DataGridEditApi interface of @salmonui/data-grid: Editing methods of the DataGrid instance.

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

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

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

## Reference

Kind: interface

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

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. Without a row id: the first selected row. |
| `save` | `save(): CommandResult;` |  | Saves: the active row or cell; in batch mode every pending change. |
| `saveCell` | `saveCell(): CommandResult;` |  | Commits the active editor only (batch mode keeps the change pending). |
| `cancelEdit` | `cancelEdit(): CommandResult;` |  | Discards the active editor; in batch mode without an open editor, every pending change. |
| `addRow` | `addRow(row?: Readonly<Record<string, unknown>>, index?: number): CommandResult;` |  | Index 0 adds at the top, at or past the end at the bottom. |
| `deleteRows` | `deleteRows(rowIds?: RowId \| readonly RowId[]): CommandResult;` |  | Without ids: the selected rows. Batch mode marks the rows until save. |
| `updateRow` | `updateRow(rowId: RowId, row: Readonly<Record<string, unknown>>): CommandResult;` |  |  |
| `updateCell` | `updateCell(rowId: RowId, field: string, value: unknown): CommandResult;` |  | Edits a cell as a user would (draft in batch mode). |
| `setCellValue` | `setCellValue(rowId: RowId, field: string, value: unknown): CommandResult;` |  | Silent data updates without the edit lifecycle (local sources). |
| `setRowData` | `setRowData(rowId: RowId, row: Row): CommandResult;` |  |  |
| `applyChanges` | `applyChanges(changes: EditDataChanges<Row>): CommandResult;` |  |  |
| `getPendingChanges` | `getPendingChanges(): EditBatchChanges<Row>;` |  |  |
| `getBatchPreview` | `getBatchPreview(): EditPreview \| undefined;` |  |  |
| `getEditSnapshot` | `getEditSnapshot(): EditSnapshot \| undefined;` |  |  |
| `hasUnsavedChanges` | `hasUnsavedChanges(): boolean;` |  |  |
| `whenEditSettled` | `whenEditSettled(): Promise<void>;` |  |  |
| `validateBatch` | `validateBatch(): Promise<boolean>;` |  | Validates every pending change without saving; resolves true when valid. |
| `undo` | `undo(): CommandResult;` |  | Undoes the last edit (needs `editing.undo`). |
| `redo` | `redo(): CommandResult;` |  |  |
| `fillSelection` | `fillSelection(rowId: RowId, field: string): CommandResult;` |  | Fills the selected cell range's content over the range extended to `field` of `rowId` (fill handle). |
| `copy` | `copy: (options?: DataGridCopyOptions \| undefined) => CommandResult;` | inherited | 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`). |
| `paste` | `paste: (text?: string \| undefined) => CommandResult;` | inherited | 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. |
