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 aninit callback to the <Gantt> component. The callback receives the IApi instance immediately after mount.
IApi interface):
TypeScript definition
Methods
exec()
Executes a Gantt action programmatically. See Actions for all available actions and their parameters.The action name, e.g.
"add-task", "update-task", "select-task".Parameters for the action. The type is inferred from
TMethodsConfig based on the action name.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.The action name to listen to.
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).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. Returnfalse from the callback to cancel the action entirely.
The action name to intercept.
Called with the action parameters before the action is processed. Return
false to prevent the action from executing.Optional configuration. Set
config.tag for grouped removal.detach()
Removes allon() and intercept() listeners associated with the given tag.
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.
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.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.ITableApi | Promise<ITableApi>
getTask()
Returns a task object by ID from the current state.The task ID to look up.
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[]