View as Markdown

API reference: @salmonui/gantt

GanttApiinterface

import type { GanttApi } from '@salmonui/gantt';
interface GanttApi<Row = Record<string, unknown>> extends Omit<DataGridApi<Row>, 'cancelEdit' | 'getState' | 'restoreState' | 'exportToExcel' | 'exportToCsv' | 'exportToPdf' | 'print' | 'undo' | 'redo' | 'setLoading'> {
    readonly grid: DataGridApi<Row>;
    getTask(id: RowId): Row | undefined;
    getTaskInfo(id: RowId): GanttTaskInfo | undefined;
    getViewRows(): readonly Row[];
    getCriticalTasks(): readonly Row[];
    formatDuration(id: RowId): string;
    formatWork(id: RowId): string;
    addTask(task?: Partial<Row>, options?: {
        readonly position?: 'top' | 'bottom' | 'above' | 'below' | 'child';
        readonly targetId?: RowId;
    }): GanttActionResult;
    updateTask(id: RowId, changes: Partial<Row>): GanttActionResult;
    deleteTasks(ids: RowId | readonly RowId[]): GanttActionResult;
    changeTaskId(id: RowId, newId: RowId): GanttActionResult;
    cancelEdit(): void;
    indent(ids: RowId | readonly RowId[]): GanttActionResult;
    outdent(ids: RowId | readonly RowId[]): GanttActionResult;
    moveTasks(ids: RowId | readonly RowId[], targetId: RowId, position: 'above' | 'below' | 'child'): GanttActionResult;
    addDependency(taskId: RowId, dependency: Dependency | string): GanttActionResult;
    removeDependency(taskId: RowId, predecessorId: RowId): GanttActionResult;
    updateDependencies(taskId: RowId, dependencies: readonly Dependency[] | string): GanttActionResult;
    splitTask(id: RowId, date: GanttDateInput): GanttActionResult;
    mergeSegments(id: RowId, segmentIndexes: readonly number[]): GanttActionResult;
    convertToMilestone(id: RowId): GanttActionResult;
    convertToTask(id: RowId): GanttActionResult;
    setTaskMode(id: RowId, mode: 'auto' | 'manual'): GanttActionResult;
    setProjectDates(start: GanttDateInput, end: GanttDateInput): void;
    expandAll(): void;
    collapseAll(): void;
    expandRows(ids: RowId | readonly RowId[]): void;
    collapseRows(ids: RowId | readonly RowId[]): void;
    zoomIn(): void;
    zoomOut(): void;
    zoomToFit(): void;
    getZoom(): number;
    extendTimeline(side: 'start' | 'end'): void;
    scrollToDate(date: GanttDateInput): void;
    scrollToTask(id: RowId): void;
    scrollTo(options: {
        readonly top?: number;
        readonly left?: number;
    }): void;
    setSplitterPosition(position: number | string): void;
    openAddDialog(): void;
    openEditDialog(id: RowId): void;
    closeDialog(): void;
    undo(): void;
    redo(): void;
    getUndoActions(): readonly string[];
    getRedoActions(): readonly string[];
    clearUndo(): void;
    clearRedo(): void;
    setLoading(loading: boolean): void;
    getState(): GanttState;
    restoreState(state: GanttState): void;
    exportToExcel(options?: GanttGridExportOptions<Row> & {
        readonly sheetName?: string;
    }): Promise<GanttExportFile<Uint8Array> | null>;
    exportToCsv(options?: GanttGridExportOptions<Row> & {
        readonly separator?: string;
        readonly escapeFormulas?: boolean;
    }): Promise<GanttExportFile<string> | null>;
    exportToPdf(options?: GanttPdfExportOptions<Row>): Promise<GanttExportFile<Uint8Array> | null>;
    print(): void;
    getTaskbarElement(id: RowId): HTMLElement | null;
    getChartElement(): HTMLElement | null;
}

ref; extends the grid pane's DataGridApi.

GanttApi members (186, 131 inherited)
NameSignatureDescription
gridreadonly grid: DataGridApi<Row>;
getTaskgetTask(id: RowId): Row | undefined;
getTaskInfogetTaskInfo(id: RowId): GanttTaskInfo | undefined;
getViewRowsgetViewRows(): readonly Row[];
getCriticalTasksgetCriticalTasks(): readonly Row[];
formatDurationformatDuration(id: RowId): string;
formatWorkformatWork(id: RowId): string;
addTaskaddTask(task?: Partial<Row>, options?: { readonly position?: 'top' | 'bottom' | 'above' | 'below' | 'child'; readonly targetId?: RowId; }): GanttActionResult;
updateTaskupdateTask(id: RowId, changes: Partial<Row>): GanttActionResult;
deleteTasksdeleteTasks(ids: RowId | readonly RowId[]): GanttActionResult;
changeTaskIdchangeTaskId(id: RowId, newId: RowId): GanttActionResult;
cancelEditcancelEdit(): void;
indentindent(ids: RowId | readonly RowId[]): GanttActionResult;
outdentoutdent(ids: RowId | readonly RowId[]): GanttActionResult;
moveTasksmoveTasks(ids: RowId | readonly RowId[], targetId: RowId, position: 'above' | 'below' | 'child'): GanttActionResult;
addDependencyaddDependency(taskId: RowId, dependency: Dependency | string): GanttActionResult;
removeDependencyremoveDependency(taskId: RowId, predecessorId: RowId): GanttActionResult;
updateDependenciesupdateDependencies(taskId: RowId, dependencies: readonly Dependency[] | string): GanttActionResult;
splitTasksplitTask(id: RowId, date: GanttDateInput): GanttActionResult;
mergeSegmentsmergeSegments(id: RowId, segmentIndexes: readonly number[]): GanttActionResult;
convertToMilestoneconvertToMilestone(id: RowId): GanttActionResult;
convertToTaskconvertToTask(id: RowId): GanttActionResult;
setTaskModesetTaskMode(id: RowId, mode: 'auto' | 'manual'): GanttActionResult;
setProjectDatessetProjectDates(start: GanttDateInput, end: GanttDateInput): void;
expandAllexpandAll(): void;
collapseAllcollapseAll(): void;
expandRowsexpandRows(ids: RowId | readonly RowId[]): void;
collapseRowscollapseRows(ids: RowId | readonly RowId[]): void;
zoomInzoomIn(): void;
zoomOutzoomOut(): void;
zoomToFitzoomToFit(): void;
getZoomgetZoom(): number;
extendTimelineextendTimeline(side: 'start' | 'end'): void;
scrollToDatescrollToDate(date: GanttDateInput): void;
scrollToTaskscrollToTask(id: RowId): void;
scrollToscrollTo(options: { readonly top?: number; readonly left?: number; }): void;
setSplitterPositionsetSplitterPosition(position: number | string): void;
openAddDialogopenAddDialog(): void;
openEditDialogopenEditDialog(id: RowId): void;
closeDialogcloseDialog(): void;
undoundo(): void;
redoredo(): void;
getUndoActionsgetUndoActions(): readonly string[];
getRedoActionsgetRedoActions(): readonly string[];
clearUndoclearUndo(): void;
clearRedoclearRedo(): void;
setLoadingsetLoading(loading: boolean): void;
getStategetState(): GanttState;
restoreStaterestoreState(state: GanttState): void;
exportToExcelexportToExcel(options?: GanttGridExportOptions<Row> & { readonly sheetName?: string; }): Promise<GanttExportFile<Uint8Array> | null>;

The grid pane's Excel export with the Data Grid cell / headerCell hooks; tree rows as outline levels.

exportToCsvexportToCsv(options?: GanttGridExportOptions<Row> & { readonly separator?: string; readonly escapeFormulas?: boolean; }): Promise<GanttExportFile<string> | null>;
exportToPdfexportToPdf(options?: GanttPdfExportOptions<Row>): Promise<GanttExportFile<Uint8Array> | null>;
printprint(): void;
getTaskbarElementgetTaskbarElement(id: RowId): HTMLElement | null;
getChartElementgetChartElement(): HTMLElement | null;
getColumninheritedgetColumn: (fieldOrId: string) => CompiledColumn<Row> | undefined;

Leaf column by column id, else the first leaf with that field.

getColumnsinheritedgetColumns: () => readonly CompiledColumn<Row>[];

Every leaf column in definition order, including hidden ones.

getVisibleColumnsinheritedgetVisibleColumns: () => readonly CompiledColumn<Row>[];

Visible leaves in runtime order.

getHiddenColumnsinheritedgetHiddenColumns: () => readonly CompiledColumn<Row>[];

Leaves hidden at runtime, in definition order.

getColumnAtinheritedgetColumnAt: (index: number) => CompiledColumn<Row> | undefined;

Visible leaf at an index of getVisibleColumns().

getColumnIndexinheritedgetColumnIndex: (fieldOrId: string) => number;

Index of a column in getVisibleColumns(), or -1.

showColumnsinheritedshowColumns: (fieldsOrIds: string | readonly string[]) => CommandResult;
hideColumnsinheritedhideColumns: (fieldsOrIds: string | readonly string[]) => CommandResult;
getFilteredRowsinheritedgetFilteredRows: () => readonly Row[];

Rows passing search and every filter, in sort order, across every page, as raw references. Without the filter module, every row.

getRowinheritedgetRow: (rowId: string) => Row | undefined;
getRowIndexinheritedgetRowIndex: (rowId: string) => number;

Visible index of a row, or -1.

getRowIdAtinheritedgetRowIdAt: (index: number) => string | undefined;

Row id at a visible index (the inverse of getRowIndex), or undefined.

getCellinheritedgetCell: (rowId: string, field: string) => CellSnapshot | undefined;
getDataSourceinheritedgetDataSource: () => DataSource<Row>;
getPrimaryKeyFieldsinheritedgetPrimaryKeyFields: () => readonly string[];

field of each primaryKey leaf column, in column order.

getColumnFacetinheritedgetColumnFacet: (field: string, options?: FacetOptions | undefined) => ColumnFacet | undefined;

Distinct values with counts for checkbox / Excel filters, or undefined without the filter module.

getPageInfoinheritedgetPageInfo: () => PageInfo | undefined;

Pager model, or undefined without the paging module.

groupColumninheritedgroupColumn: (field: string, index?: number | undefined) => CommandResult;

Needs the grouping module.

ungroupColumninheritedungroupColumn: (field: string) => CommandResult;
clearGroupinginheritedclearGrouping: () => CommandResult;
toggleGroupinheritedtoggleGroup: (group: GroupTarget, expanded?: boolean | undefined) => CommandResult;

Toggles (or sets) one group by row id, path key, or path.

expandAllGroupsinheritedexpandAllGroups: () => CommandResult;
collapseAllGroupsinheritedcollapseAllGroups: () => CommandResult;
getGroupinheritedgetGroup: (rowId: string) => GroupRowSnapshot | undefined;

Caption or footer snapshot of a group row id, or undefined.

getAggregatesinheritedgetAggregates: (groupId?: string | undefined) => Readonly<Record<string, Readonly<Record<string, unknown>>>> | undefined;

Without an argument the footer aggregates (undefined without the aggregates module); with a group row id that group's aggregates (undefined for an unknown id).

refreshinheritedrefresh: () => void;

Re-reads the data with the current query and keeps the grid state: engine.refresh().

disposeinheriteddispose: () => void;
resetStateinheritedresetState: () => RestoreResult;

Restores the state captured when this API was created.

pinColumninheritedpinColumn: (field: string, pinned: DataGridColumnPin | null) => CommandResult;

Pins a column (id or field) to a side or unpins it (null).

openColumnChooserinheritedopenColumnChooser: (position?: { readonly x: number; readonly y: number; } | undefined) => void;

Opens the column chooser; at the given viewport point, else at the grid start.

openColumnMenuinheritedopenColumnMenu: (field: string) => void;
openFilterMenuinheritedopenFilterMenu: (field: string) => void;
closeOverlaysinheritedcloseOverlays: () => void;

Closes any open menu, dialog, or chooser (focus returns to its invoker).

registerCommandHandlerinheritedregisterCommandHandler: (command: DataGridUiCommand | (string & {}), handler: DataGridCommandHandler) => () => void;

Registers the handler of a UI command (toolbar, menus); returns the unregister function.

runCommandinheritedrunCommand: (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.

getHeaderElementinheritedgetHeaderElement: (field: string) => HTMLElement | null;

Header cell of a column (id or field); null outside the rendered window.

getPartElementinheritedgetPartElement: (part: DataGridPart) => HTMLElement | null;

First rendered element of a part; null when it is not rendered.

openSortDialoginheritedopenSortDialog: () => void;

Opens the sort sheet (showAdaptiveSortDialog).

openFilterDialoginheritedopenFilterDialog: (field?: string | undefined) => void;

Opens the filter sheet of field, or the list of filterable columns (showAdaptiveFilterDialog).

isAdaptiveinheritedisAdaptive: () => boolean;

True while the adaptive layout applies (derived from the measured container width). Salmon

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.

startEditinheritedstartEdit: (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.

saveinheritedsave: () => CommandResult;

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

saveCellinheritedsaveCell: () => CommandResult;

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

addRowinheritedaddRow: (row?: Readonly<Record<string, unknown>> | undefined, index?: number | undefined) => CommandResult;

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

deleteRowsinheriteddeleteRows: (rowIds?: string | readonly string[] | undefined) => CommandResult;

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

updateRowinheritedupdateRow: (rowId: string, row: Readonly<Record<string, unknown>>) => CommandResult;
updateCellinheritedupdateCell: (rowId: string, field: string, value: unknown) => CommandResult;

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

setCellValueinheritedsetCellValue: (rowId: string, field: string, value: unknown) => CommandResult;

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

setRowDatainheritedsetRowData: (rowId: string, row: Row) => CommandResult;
applyChangesinheritedapplyChanges: (changes: EditDataChanges<Row>) => CommandResult;
getPendingChangesinheritedgetPendingChanges: () => EditBatchChanges<Row>;
getBatchPreviewinheritedgetBatchPreview: () => EditPreview | undefined;
getEditSnapshotinheritedgetEditSnapshot: () => EditSnapshot | undefined;
hasUnsavedChangesinheritedhasUnsavedChanges: () => boolean;
whenEditSettledinheritedwhenEditSettled: () => Promise<void>;
validateBatchinheritedvalidateBatch: () => Promise<boolean>;

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

fillSelectioninheritedfillSelection: (rowId: string, field: string) => CommandResult;

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

sortColumninheritedsortColumn: (field: string, direction: DataGridSortDirection, options?: { multiple?: boolean; } | undefined) => CommandResult;

Sorts by a column; multiple adds it to a multi-column sort.

removeSortinheritedremoveSort: (field: string) => CommandResult;
clearSortinginheritedclearSorting: () => CommandResult;
filterColumninheritedfilterColumn: (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).

removeFilterinheritedremoveFilter: (field: string) => CommandResult;

Removes the filters of one column.

clearFilteringinheritedclearFiltering: (fields?: string | readonly string[] | undefined) => CommandResult;

Removes the filters of the given columns, or every filter.

searchinheritedsearch: (text: string) => CommandResult;
clearSearchinheritedclearSearch: () => CommandResult;
goToPageinheritedgoToPage: (page: number) => CommandResult;
setPageSizeinheritedsetPageSize: (pageSize: number) => CommandResult;
expandDetailinheritedexpandDetail: (rowId: string) => CommandResult;
collapseDetailinheritedcollapseDetail: (rowId: string) => CommandResult;
toggleDetailinheritedtoggleDetail: (rowId: string, expanded?: boolean | undefined) => CommandResult;

Toggles one detail row; expanded forces a state.

expandAllDetailsinheritedexpandAllDetails: () => CommandResult;
collapseAllDetailsinheritedcollapseAllDetails: () => CommandResult;
isDetailExpandedinheritedisDetailExpanded: (rowId: string) => boolean;
getChildGridinheritedgetChildGrid: (rowId: string) => DataGridApi<unknown> | null;

The mounted child grid of a parent row (null when collapsed or not rendered).

moveRowsinheritedmoveRows: (rowIds: string | readonly string[], to: number | DataGridMoveTarget) => CommandResult;

Moves rows so the first one ends at data row index toIndex, or next to / into a target row ({ targetRowId, position }; into makes them the last children of the target in tree mode).

expandAllTreeRowsinheritedexpandAllTreeRows: () => CommandResult;
collapseAllTreeRowsinheritedcollapseAllTreeRows: () => CommandResult;
expandTreeLevelinheritedexpandTreeLevel: (depth: number) => CommandResult;

Expands the parents at depth (0: roots).

collapseTreeLevelinheritedcollapseTreeLevel: (depth: number) => CommandResult;
expandTreeRowsinheritedexpandTreeRows: (rowIds: string | readonly string[]) => CommandResult;
collapseTreeRowsinheritedcollapseTreeRows: (rowIds: string | readonly string[]) => CommandResult;
toggleTreeRowinheritedtoggleTreeRow: (rowId: string, expanded?: boolean | undefined) => CommandResult;
indentRowsinheritedindentRows: (rowIds: string | readonly string[]) => CommandResult;

Moves rows under their previous sibling.

outdentRowsinheritedoutdentRows: (rowIds: string | readonly string[]) => CommandResult;

Moves rows after their parent, as its siblings.

getTreeRowinheritedgetTreeRow: (rowId: string) => DataGridTreeRowInfo | null;
getChildRowsinheritedgetChildRows: (rowId: string | null) => readonly Row[];

Kept children of a row in view order (null: the roots).

reloadTreeChildreninheritedreloadTreeChildren: (rowId: string) => CommandResult;

Salmon: retries a failed lazy child load.

getVisibleRowsinheritedgetVisibleRows: () => readonly Row[];

Visible data rows in view order.

pinRowsinheritedpinRows: (rowIds: string | readonly string[]) => CommandResult;

Pins rows to the top zone (rejected unless isRowPinned or defaultPinnedRows is set).

unpinRowsinheritedunpinRows: (rowIds: string | readonly string[]) => CommandResult;

Unpins rows, also rows isRowPinned matches.

isRowPinnedinheritedisRowPinned: (rowId: string) => boolean;

True when the row is pinned, whether or not the current filter shows it.

getPinnedRowIdsinheritedgetPinnedRowIds: () => readonly string[];

Ids of the pinned rows shown, in display order.

openFilterBuilderinheritedopenFilterBuilder: () => void;

Opens the filter builder dialog. Ignored unless filtering.builder is set.

closeFilterBuilderinheritedcloseFilterBuilder: () => void;

Closes the filter builder dialog without applying.

getViewportinheritedgetViewport: () => DataGridViewport;

Scroll sync extension point: the current body viewport.

subscribeViewportinheritedsubscribeViewport: (listener: () => void) => () => void;

Calls listener outside React on every body scroll and layout change; returns the unsubscribe function.

getRowOffsetsinheritedgetRowOffsets: () => RowMetrics;

Row height extension point: the row offsets of the visible row model (the body's own prefix sums).

getPageSizeForHeightinheritedgetPageSizeForHeight: (height: number) => number;

Whole data rows that fit in height px after the toolbar, group drop area, header rows, footer aggregate rows and pager; 0 when none fit. Rows count rowHeight (the estimate with measured rows, the card height in adaptive vertical mode). Before mount only the header and footer rows are subtracted.

selectRowsinheritedselectRows: (rowIds: string | readonly string[], options?: { mode?: "add" | "remove" | "replace" | "toggle"; } | undefined) => CommandResult;
selectRowRangeinheritedselectRowRange: (fromRowId: string, toRowId: string, options?: { mode?: "add" | "replace"; } | undefined) => CommandResult;
selectAllinheritedselectAll: (options?: { scope?: "filtered" | "page"; } | undefined) => CommandResult;

page: every row of the current page (all rows without paging). filtered (default with paging off): every row matching the query, O(1).

clearSelectioninheritedclearSelection: (parts?: { rows?: boolean; cells?: boolean; columns?: boolean; } | undefined) => CommandResult;
selectCellsinheritedselectCells: (cells: readonly DataGridCellKey[], options?: { mode?: "add" | "replace" | "toggle"; } | undefined) => CommandResult;
selectCellRangeinheritedselectCellRange: (anchor: DataGridCellKey, focus: DataGridCellKey, options?: { mode?: "add" | "replace"; } | undefined) => CommandResult;
selectColumnsinheritedselectColumns: (fields: string | readonly string[], options?: { mode?: "add" | "replace" | "toggle"; } | undefined) => CommandResult;
isRowSelectedinheritedisRowSelected: (rowId: string) => boolean;
getSelectedRowIdsinheritedgetSelectedRowIds: () => readonly string[];
getSelectedRowsinheritedgetSelectedRows: () => readonly Row[];

Raw rows, in the order of getSelectedRowIds().

getSelectedCellsinheritedgetSelectedCells: () => readonly DataGridCellKey[];
getSelectedColumnsinheritedgetSelectedColumns: () => readonly string[];
getSelectioninheritedgetSelection: () => SerializedSelection | undefined;

Serializable selection (scope, ids or excluded ids, cell ranges, columns).

setSelectioninheritedsetSelection: (selection: SerializedSelection) => CommandResult;
getSelectionSummaryinheritedgetSelectionSummary: () => SelectionSummary | undefined;
engineinheritedengine: DataGridApiEngine<Row>;

The engine, with the façades of the optional modules a prop registers (infiniteScroll).

elementinheritedelement: HTMLDivElement | null;

The root element; null before mount and after unmount.

focusinheritedfocus: () => 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).

focusCellinheritedfocusCell: (rowId: string, field: string) => void;

Scrolls the cell into view and focuses it.

focusHeaderinheritedfocusHeader: (field: string) => void;
getFocusedCellinheritedgetFocusedCell: () => DataGridFocusedCell | null;
registerKeyHandlerinheritedregisterKeyHandler: (command: string, handler: DataGridKeyHandler, options?: { priority?: number; } | undefined) => () => void;

Registers a handler for a keyboard command (DEFAULT_KEY_BINDINGS); higher priority runs first. Returns the unregister function.

getRowInfoinheritedgetRowInfo: (target: string | Element | EventTarget | null) => DataGridRowInfo<Row> | undefined;

Row info by row id, or by any element inside a row (cell, custom template content).

getRowElementinheritedgetRowElement: (rowId: string) => HTMLElement | null;
getCellElementinheritedgetCellElement: (rowId: string, field: string) => HTMLElement | null;
scrollToRowinheritedscrollToRow: (rowId: string, options?: DataGridScrollOptions | undefined) => void;
scrollToColumninheritedscrollToColumn: (field: string, options?: DataGridScrollOptions | undefined) => void;
autoSizeColumnsinheritedautoSizeColumns: (fields?: string | readonly string[] | undefined) => void;

Fits widths to header and rendered content; every visible column when omitted.

setColumnWidthinheritedsetColumnWidth: (field: string, width: number) => CommandResult;
moveColumninheritedmoveColumn: (field: string, toIndex: number) => CommandResult;
getRenderedRangeinheritedgetRenderedRange: () => { readonly rows: VirtualRange; readonly columns: VirtualRange; };

Rendered row range and center column range (overscan included).