IApi) is the primary interface for interacting with the Gantt component at runtime. You can obtain it in two ways:
api.exec(action, data)
Dispatches an action to the Gantt store. Actions trigger data mutations and fire corresponding events that listeners can react to.The name of the action to dispatch. See the Actions reference for all available action names.
The payload for the action. Shape depends on the specific action.
api.on(event, handler)
Subscribes to an event fired after an action completes. Returns a handler reference that can be passed toapi.detach() to unsubscribe.
The name of the event to listen for. See the Events reference for all available event names.
Callback invoked with the event payload whenever the event fires.
The same handler function, which can be passed to
api.detach() to remove the listener.api.intercept(event, handler)
Registers an interceptor that runs before the action is committed to the store. Returningfalse (or a falsy value) from the handler cancels the action entirely.
The name of the action to intercept.
Called with the action payload. Return
false to block the action, or any truthy value (or nothing) to allow it.api.detach(handler)
Removes a previously registered event listener or interceptor.The handler reference originally returned by
api.on() or passed to api.intercept().api.getState()
Returns a synchronous snapshot of the current Gantt state. Useful for reading data outside of event handlers.A plain object containing the current Gantt state, including tasks, links, zoom level, selection, and more.
api.getReactiveState()
Returns a reactive state store. Each property is a subscribable store (writable/readable). Useful for binding Gantt state to your own UI components.An object of reactive stores. Each store exposes a
.subscribe(callback) method.api.getTask(id)
Retrieves a single task by its ID.The ID of the task to retrieve.
The task object, including any internal computed fields (
$x, $y, $w, $h, $level, etc.).api.serialize()
Exports the current task data as a plain array of task objects, stripping all internal computed fields. Suitable for saving to a database or sending to a server.An array of plain task objects with all user-defined fields and no internal
$-prefixed fields.api.getTable(waitRender?)
Returns the underlying grid/table API. Useful for advanced grid interactions such as focusing cells or column management.When
true, returns a Promise that resolves to the table API after the next render tick. Use this when calling immediately after a state change.The table API object, or a Promise resolving to it when
waitRender is true.api.getHistory()
Requires the
undo prop to be enabled on the <Gantt> component.An object with counts of available undo and redo steps.
api.setNext(router)
Chains another event bus router after the Gantt’s internal router. This is the primary integration point for data providers (e.g.RestDataProvider) that need to intercept and relay actions to a backend.
Another event bus or data provider that implements the router interface.
The newly appended router, so chains can be built incrementally.