API reference: @salmonui/data-grid
DataGridApiinterface
import type { DataGridApi } from '@salmonui/data-grid';interface DataGridApi<Row = unknown> extends Omit<CoreDataGridApi<Row>, 'engine' | 'getRowInfo' | keyof DataGridQueryApi>, DataGridSelectionApi<Row>, DataGridChromeApi, DataGridQueryApi, DataGridStateMethods, DataGridEditApi<Row>, DataGridOutputApi<Row>, DataGridAdaptiveApi, DataGridDetailApi, DataGridRowPinningApi, DataGridDataUiApi, DataGridFilterBuilderApi, DataGridViewApi, DataGridTreeApi<Row> {
readonly engine: DataGridApiEngine<Row>;
readonly element: HTMLDivElement | null;
focus(): void;
focusCell(rowId: RowId, field: string): void;
focusHeader(field: string): void;
getFocusedCell(): DataGridFocusedCell | null;
registerKeyHandler(command: string, handler: DataGridKeyHandler, options?: {
priority?: number;
}): () => void;
getRowInfo(target: RowId | Element | EventTarget | null): DataGridRowInfo<Row> | undefined;
getRowElement(rowId: RowId): HTMLElement | null;
getCellElement(rowId: RowId, field: string): HTMLElement | null;
scrollToRow(rowId: RowId, options?: DataGridScrollOptions): void;
scrollToColumn(field: string, options?: DataGridScrollOptions): void;
autoSizeColumns(fields?: string | readonly string[]): void;
setColumnWidth(field: string, width: number): DataGridActionResult;
moveColumn(field: string, toIndex: number): DataGridActionResult;
getRenderedRange(): {
readonly rows: VirtualRange;
readonly columns: VirtualRange;
};
}
Imperative DataGrid API (ref, useDataGridApi()).
| Name | Signature | Description |
|---|---|---|
engine | readonly engine: DataGridApiEngine<Row>; | The engine, with the façades of the optional modules a prop registers ( |
element | readonly element: HTMLDivElement | null; | The root element; null before mount and after unmount. |
focus | focus(): void; | Focuses the grid content: the focused body cell, else the last focused body cell, else the first body cell (also from the header, like Alt+W). |
focusCell | focusCell(rowId: RowId, field: string): void; | Scrolls the cell into view and focuses it. |
focusHeader | focusHeader(field: string): void; | |
getFocusedCell | getFocusedCell(): DataGridFocusedCell | null; | |
registerKeyHandler | registerKeyHandler(command: string, handler: DataGridKeyHandler, options?: {
priority?: number;
}): () => void; | Registers a handler for a keyboard command ( |
getRowInfo | getRowInfo(target: RowId | Element | EventTarget | null): DataGridRowInfo<Row> | undefined; | Row info by row id, or by any element inside a row (cell, custom template content). |
getRowElement | getRowElement(rowId: RowId): HTMLElement | null; | |
getCellElement | getCellElement(rowId: RowId, field: string): HTMLElement | null; | |
scrollToRow | scrollToRow(rowId: RowId, options?: DataGridScrollOptions): void; | |
scrollToColumn | scrollToColumn(field: string, options?: DataGridScrollOptions): void; | |
autoSizeColumns | autoSizeColumns(fields?: string | readonly string[]): void; | Fits widths to header and rendered content; every visible column when omitted. |
setColumnWidth | setColumnWidth(field: string, width: number): DataGridActionResult; | |
moveColumn | moveColumn(field: string, toIndex: number): DataGridActionResult; | |
getRenderedRange | getRenderedRange(): {
readonly rows: VirtualRange;
readonly columns: VirtualRange;
}; | Rendered row range and center column range (overscan included). |
getColumninherited | getColumn: (fieldOrId: string) => CompiledColumn<Row> | undefined; | Leaf column by column id, else the first leaf with that |
getColumnsinherited | getColumns: () => readonly CompiledColumn<Row>[]; | Every leaf column in definition order, including hidden ones. |
getVisibleColumnsinherited | getVisibleColumns: () => readonly CompiledColumn<Row>[]; | Visible leaves in runtime order. |
getHiddenColumnsinherited | getHiddenColumns: () => readonly CompiledColumn<Row>[]; | Leaves hidden at runtime, in definition order. |
getColumnAtinherited | getColumnAt: (index: number) => CompiledColumn<Row> | undefined; | Visible leaf at an index of |
getColumnIndexinherited | getColumnIndex: (fieldOrId: string) => number; | Index of a column in |
showColumnsinherited | showColumns: (fieldsOrIds: string | readonly string[]) => CommandResult; | |
hideColumnsinherited | hideColumns: (fieldsOrIds: string | readonly string[]) => CommandResult; | |
getViewRowsinherited | getViewRows: () => readonly Row[]; | Rows of the current view (after the query pipeline), as raw references. |
getFilteredRowsinherited | getFilteredRows: () => readonly Row[]; | Rows passing search and every filter, in sort order, across every page,
as raw references. Without the
|
getRowinherited | getRow: (rowId: string) => Row | undefined; | |
getRowIndexinherited | getRowIndex: (rowId: string) => number; | Visible index of a row, or -1. |
getRowIdAtinherited | getRowIdAt: (index: number) => string | undefined; | Row id at a visible index (the inverse of |
getCellinherited | getCell: (rowId: string, field: string) => CellSnapshot | undefined; | |
getDataSourceinherited | getDataSource: () => DataSource<Row>; | |
getPrimaryKeyFieldsinherited | getPrimaryKeyFields: () => readonly string[]; |
|
getColumnFacetinherited | getColumnFacet: (field: string, options?: FacetOptions | undefined) => ColumnFacet | undefined; | Distinct values with counts for checkbox / Excel filters, or undefined without the |
getPageInfoinherited | getPageInfo: () => PageInfo | undefined; | Pager model, or undefined without the |
groupColumninherited | groupColumn: (field: string, index?: number | undefined) => CommandResult; | Needs the |
ungroupColumninherited | ungroupColumn: (field: string) => CommandResult; | |
clearGroupinginherited | clearGrouping: () => CommandResult; | |
toggleGroupinherited | toggleGroup: (group: GroupTarget, expanded?: boolean | undefined) => CommandResult; | Toggles (or sets) one group by row id, path key, or path. |
expandAllGroupsinherited | expandAllGroups: () => CommandResult; | |
collapseAllGroupsinherited | collapseAllGroups: () => CommandResult; | |
getGroupinherited | getGroup: (rowId: string) => GroupRowSnapshot | undefined; | Caption or footer snapshot of a group row id, or undefined. |
getAggregatesinherited | getAggregates: (groupId?: string | undefined) => Readonly<Record<string, Readonly<Record<string, unknown>>>> | undefined; | Without an argument the footer aggregates (undefined without the
|
refreshinherited | refresh: () => void; | Re-reads the data with the current query and keeps the grid state: |
disposeinherited | dispose: () => void; | |
getStateinherited | getState: (options?: DataGridStateOptions | undefined) => DataGridState; | Persistable state (columns, pinning, sorting, filters, grouping, paging, search, selection, scroll). |
restoreStateinherited | restoreState: (state: string | DataGridState, options?: (DataGridStateOptions & DeserializeDataGridStateOptions) | undefined) => RestoreResult; | Restores a state (object or serialized) in one batch without recompiling columns. |
resetStateinherited | resetState: () => RestoreResult; | Restores the state captured when this API was created. |
pinColumninherited | pinColumn: (field: string, pinned: DataGridColumnPin | null) => CommandResult; | Pins a column (id or field) to a side or unpins it ( |
openColumnChooserinherited | openColumnChooser: (position?: { readonly x: number; readonly y: number; } | undefined) => void; | Opens the column chooser; at the given viewport point, else at the grid start. |
openColumnMenuinherited | openColumnMenu: (field: string) => void; | |
openFilterMenuinherited | openFilterMenu: (field: string) => void; | |
closeOverlaysinherited | closeOverlays: () => void; | Closes any open menu, dialog, or chooser (focus returns to its invoker). |
registerCommandHandlerinherited | registerCommandHandler: (command: DataGridUiCommand | (string & {}), handler: DataGridCommandHandler) => () => void; | Registers the handler of a UI command (toolbar, menus); returns the unregister function. |
runCommandinherited | runCommand: (command: DataGridUiCommand | (string & {}), payload?: Readonly<Record<string, unknown>> | undefined) => boolean; | Runs a UI command (handler, then a module command, else a dev warning). Returns true when handled. |
getHeaderElementinherited | getHeaderElement: (field: string) => HTMLElement | null; | Header cell of a column (id or field); |
getPartElementinherited | getPartElement: (part: DataGridPart) => HTMLElement | null; | First rendered element of a part; |
openSortDialoginherited | openSortDialog: () => void; | Opens the sort sheet ( |
openFilterDialoginherited | openFilterDialog: (field?: string | undefined) => void; | Opens the filter sheet of |
isAdaptiveinherited | isAdaptive: () => boolean; | True while the adaptive layout applies (derived from the measured container width). Salmon |
copyinherited | copy: (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. |
pasteinherited | paste: (text?: string | undefined) => CommandResult; | Pastes TSV |
startEditinherited | startEdit: (rowId?: string | undefined, field?: string | undefined) => CommandResult; | Row and dialog mode edit the row, batch and cell mode the cell. Without a row id: the first selected row. |
saveinherited | save: () => CommandResult; | Saves: the active row or cell; in batch mode every pending change. |
saveCellinherited | saveCell: () => CommandResult; | Commits the active editor only (batch mode keeps the change pending). |
cancelEditinherited | cancelEdit: () => CommandResult; | Discards the active editor; in batch mode without an open editor, every pending change. |
addRowinherited | addRow: (row?: Readonly<Record<string, unknown>> | undefined, index?: number | undefined) => CommandResult; | Index 0 adds at the top, at or past the end at the bottom. |
deleteRowsinherited | deleteRows: (rowIds?: string | readonly string[] | undefined) => CommandResult; | Without ids: the selected rows. Batch mode marks the rows until save. |
updateRowinherited | updateRow: (rowId: string, row: Readonly<Record<string, unknown>>) => CommandResult; | |
updateCellinherited | updateCell: (rowId: string, field: string, value: unknown) => CommandResult; | Edits a cell as a user would (draft in batch mode). |
setCellValueinherited | setCellValue: (rowId: string, field: string, value: unknown) => CommandResult; | Silent data updates without the edit lifecycle (local sources). |
setRowDatainherited | setRowData: (rowId: string, row: Row) => CommandResult; | |
applyChangesinherited | applyChanges: (changes: EditDataChanges<Row>) => CommandResult; | |
getPendingChangesinherited | getPendingChanges: () => EditBatchChanges<Row>; | |
getBatchPreviewinherited | getBatchPreview: () => EditPreview | undefined; | |
getEditSnapshotinherited | getEditSnapshot: () => EditSnapshot | undefined; | |
hasUnsavedChangesinherited | hasUnsavedChanges: () => boolean; | |
whenEditSettledinherited | whenEditSettled: () => Promise<void>; | |
validateBatchinherited | validateBatch: () => Promise<boolean>; | Validates every pending change without saving; resolves true when valid. |
undoinherited | undo: () => CommandResult; | Undoes the last edit (needs |
redoinherited | redo: () => CommandResult; | |
fillSelectioninherited | fillSelection: (rowId: string, field: string) => CommandResult; | Fills the selected cell range's content over the range extended to |
sortColumninherited | sortColumn: (field: string, direction: DataGridSortDirection, options?: { multiple?: boolean; } | undefined) => CommandResult; | Sorts by a column; |
removeSortinherited | removeSort: (field: string) => CommandResult; | |
clearSortinginherited | clearSorting: () => CommandResult; | |
filterColumninherited | filterColumn: (field: string, operator: DataGridFilterOperator, value: Json, options?: { logic?: "and" | "or"; matchCase?: boolean; ignoreAccents?: boolean; } | undefined) => CommandResult; | Replaces the column's top-level conditions with one condition (an array value with a scalar operator ORs one condition per value). |
removeFilterinherited | removeFilter: (field: string) => CommandResult; | Removes the filters of one column. |
clearFilteringinherited | clearFiltering: (fields?: string | readonly string[] | undefined) => CommandResult; | Removes the filters of the given columns, or every filter. |
searchinherited | search: (text: string) => CommandResult; | |
clearSearchinherited | clearSearch: () => CommandResult; | |
goToPageinherited | goToPage: (page: number) => CommandResult; | |
setPageSizeinherited | setPageSize: (pageSize: number) => CommandResult; | |
expandDetailinherited | expandDetail: (rowId: string) => CommandResult; | |
collapseDetailinherited | collapseDetail: (rowId: string) => CommandResult; | |
toggleDetailinherited | toggleDetail: (rowId: string, expanded?: boolean | undefined) => CommandResult; | Toggles one detail row; |
expandAllDetailsinherited | expandAllDetails: () => CommandResult; | |
collapseAllDetailsinherited | collapseAllDetails: () => CommandResult; | |
isDetailExpandedinherited | isDetailExpanded: (rowId: string) => boolean; | |
getChildGridinherited | getChildGrid: (rowId: string) => DataGridApi<unknown> | null; | The mounted child grid of a parent row (null when collapsed or not rendered). |
moveRowsinherited | moveRows: (rowIds: string | readonly string[], to: number | DataGridMoveTarget) => CommandResult; | Moves rows so the first one ends at data row index |
exportToExcelinherited | exportToExcel: (options?: DataGridExcelExportOptions<Row> | undefined) => Promise<ExportFile<Uint8Array<ArrayBufferLike>> | null>; | XLSX export ( |
exportToPdfinherited | exportToPdf: (options?: DataGridPdfExportOptions<Row> | undefined) => Promise<ExportFile<Uint8Array<ArrayBufferLike>> | null>; | PDF export ( |
exportToCsvinherited | exportToCsv: (options?: DataGridCsvExportOptions<Row> | undefined) => Promise<ExportFile<string> | null>; | CSV export ( |
printinherited | print: (options?: DataGridPrintOptions<Row> | undefined) => Promise<boolean>; | Prints the grid (every row of the scope, no virtualization). Resolves false when prevented or outside a browser. |
setLoadinginherited | setLoading: (loading: boolean) => void; | Shows the loading indicator until |
expandAllTreeRowsinherited | expandAllTreeRows: () => CommandResult; | |
collapseAllTreeRowsinherited | collapseAllTreeRows: () => CommandResult; | |
expandTreeLevelinherited | expandTreeLevel: (depth: number) => CommandResult; | Expands the parents at |
collapseTreeLevelinherited | collapseTreeLevel: (depth: number) => CommandResult; | |
expandTreeRowsinherited | expandTreeRows: (rowIds: string | readonly string[]) => CommandResult; | |
collapseTreeRowsinherited | collapseTreeRows: (rowIds: string | readonly string[]) => CommandResult; | |
toggleTreeRowinherited | toggleTreeRow: (rowId: string, expanded?: boolean | undefined) => CommandResult; | |
indentRowsinherited | indentRows: (rowIds: string | readonly string[]) => CommandResult; | Moves rows under their previous sibling. |
outdentRowsinherited | outdentRows: (rowIds: string | readonly string[]) => CommandResult; | Moves rows after their parent, as its siblings. |
getTreeRowinherited | getTreeRow: (rowId: string) => DataGridTreeRowInfo | null; | |
getChildRowsinherited | getChildRows: (rowId: string | null) => readonly Row[]; | Kept children of a row in view order ( |
reloadTreeChildreninherited | reloadTreeChildren: (rowId: string) => CommandResult; | Salmon: retries a failed lazy child load. |
getVisibleRowsinherited | getVisibleRows: () => readonly Row[]; | Visible data rows in view order. |
pinRowsinherited | pinRows: (rowIds: string | readonly string[]) => CommandResult; | Pins rows to the top zone (rejected unless |
unpinRowsinherited | unpinRows: (rowIds: string | readonly string[]) => CommandResult; | Unpins rows, also rows |
isRowPinnedinherited | isRowPinned: (rowId: string) => boolean; | True when the row is pinned, whether or not the current filter shows it. |
getPinnedRowIdsinherited | getPinnedRowIds: () => readonly string[]; | Ids of the pinned rows shown, in display order. |
openFilterBuilderinherited | openFilterBuilder: () => void; | Opens the filter builder dialog.
Ignored unless |
closeFilterBuilderinherited | closeFilterBuilder: () => void; | Closes the filter builder dialog without applying. |
getViewportinherited | getViewport: () => DataGridViewport; | Scroll sync extension point: the current body viewport. |
subscribeViewportinherited | subscribeViewport: (listener: () => void) => () => void; | Calls |
getRowOffsetsinherited | getRowOffsets: () => RowMetrics; | Row height extension point: the row offsets of the visible row model (the body's own prefix sums). |
scrollToinherited | scrollTo: (options: DataGridScrollToOptions) => void; | Scrolls the body to an offset. An omitted axis keeps its position; offsets are clamped to the scroll range. |
getPageSizeForHeightinherited | getPageSizeForHeight: (height: number) => number; | Whole data rows that fit in |
selectRowsinherited | selectRows: (rowIds: string | readonly string[], options?: { mode?: "add" | "remove" | "replace" | "toggle"; } | undefined) => CommandResult; | |
selectRowRangeinherited | selectRowRange: (fromRowId: string, toRowId: string, options?: { mode?: "add" | "replace"; } | undefined) => CommandResult; | |
selectAllinherited | selectAll: (options?: { scope?: "filtered" | "page"; } | undefined) => CommandResult; |
|
clearSelectioninherited | clearSelection: (parts?: { rows?: boolean; cells?: boolean; columns?: boolean; } | undefined) => CommandResult; | |
selectCellsinherited | selectCells: (cells: readonly DataGridCellKey[], options?: { mode?: "add" | "replace" | "toggle"; } | undefined) => CommandResult; | |
selectCellRangeinherited | selectCellRange: (anchor: DataGridCellKey, focus: DataGridCellKey, options?: { mode?: "add" | "replace"; } | undefined) => CommandResult; | |
selectColumnsinherited | selectColumns: (fields: string | readonly string[], options?: { mode?: "add" | "replace" | "toggle"; } | undefined) => CommandResult; | |
isRowSelectedinherited | isRowSelected: (rowId: string) => boolean; | |
getSelectedRowIdsinherited | getSelectedRowIds: () => readonly string[]; | |
getSelectedRowsinherited | getSelectedRows: () => readonly Row[]; | Raw rows, in the order of |
getSelectedCellsinherited | getSelectedCells: () => readonly DataGridCellKey[]; | |
getSelectedColumnsinherited | getSelectedColumns: () => readonly string[]; | |
getSelectioninherited | getSelection: () => SerializedSelection | undefined; | Serializable selection (scope, ids or excluded ids, cell ranges, columns). |
setSelectioninherited | setSelection: (selection: SerializedSelection) => CommandResult; | |
getSelectionSummaryinherited | getSelectionSummary: () => SelectionSummary | undefined; |