Skip to main content
The IApi interface provides programmatic access to the Gantt component. Use it to execute actions, subscribe to events, intercept and cancel actions, read state, and integrate data providers.

Obtaining the API

Pass an init callback to the <Gantt> component. The callback receives the IApi instance immediately after mount.
Alternatively, bind the component instance directly (the component exposes the same IApi interface):

TypeScript definition

Methods

exec()

Executes a Gantt action programmatically. See Actions for all available actions and their parameters.
string
required
The action name, e.g. "add-task", "update-task", "select-task".
object
Parameters for the action. The type is inferred from TMethodsConfig based on the action name.
Returns: Promise<any> — resolves after the action and all handlers have run.

on()

Subscribes to an action event. The callback fires after the action has been processed.
string
required
The action name to listen to.
(params) => any
required
Called with the action parameters after the action completes. The params object may be mutated by the store (e.g. id is set on add-task after the task is created).
IEventConfig
Optional configuration object. Set config.tag to a symbol or string to group listeners for later removal via detach().

intercept()

Registers a handler that fires before an action is processed. Return false from the callback to cancel the action entirely.
string
required
The action name to intercept.
(params) => any
required
Called with the action parameters before the action is processed. Return false to prevent the action from executing.
IEventConfig
Optional configuration. Set config.tag for grouped removal.

detach()

Removes all on() and intercept() listeners associated with the given tag.
symbol | string
required
The tag value used when registering listeners.

getState()

Returns the current internal state snapshot as a plain object. Useful for reading task lists, current selection, scroll position, and scale data. Returns: IData — the full state object.

getReactiveState()

Returns reactive Svelte writable stores for each state key. Subscribe to these in Svelte components for live updates. Returns: { [Key in keyof IData]: IPublicWritable<IData[Key]> }

setNext()

Connects a data provider (e.g. RestDataProvider) to the API event bus. The provider receives all actions and persists changes to the backend.
IEventBus<TMethodsConfig>
required
A data provider instance that implements IEventBus. Typically a RestDataProvider.

getStores()

Returns the internal data store instances. Primarily used for advanced integrations. Returns: { data: DataStore }

getTable()

Returns the underlying grid API instance for direct grid manipulation.
boolean
When true, returns a Promise that resolves after the next render cycle completes. Useful if you need to access the grid immediately after a state change.
Returns: ITableApi | Promise<ITableApi>

getTask()

Returns a task object by ID from the current state.
string | number
required
The task ID to look up.
Returns: ITask — the task object, or undefined if not found.

serialize()

Returns the current task tree as a flat array of plain task objects, suitable for saving or sending to a server. Returns: ITask[]