Skip to content

Commit 0d17615

Browse files
Merge pull request #101 from AlexKlimenkov/master
update info on vue wrapper docs
2 parents 5cf37f5 + a5b5578 commit 0d17615

6 files changed

Lines changed: 376 additions & 29 deletions

File tree

docs/integrations/vue/configuration-props.md

Lines changed: 161 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Use it as a reference after [Overview](integrations/vue/overview.md) or [Quick S
6969
<tr>
7070
<td>plugins</td>
7171
<td>GanttPlugins</td>
72-
<td>Plugin activation map (for example <code>auto_scheduling</code>).</td>
72+
<td><a href="/guides/extensions-list/">Gantt extensions</a> to activate (for example <a href="/guides/auto-scheduling/"><code>auto_scheduling</code></a>, <a href="/guides/critical-path/"><code>critical_path</code></a>).</td>
7373
</tr>
7474
<tr>
7575
<td>templates</td>
@@ -203,6 +203,21 @@ const events = {
203203
};
204204
~~~
205205

206+
The map is typed as `VueGanttEvents`. The wrapper declares the following known events with full type signatures; any other Gantt event name is also accepted (custom events are typed as string-keyed handlers).
207+
208+
| Event | Signature | Notes |
209+
|-------|-----------|-------|
210+
| `onBeforeLightbox` | `(taskId: string \| number) => boolean \| void` | Return `false` to suppress the built-in lightbox (for example to route to an external editor). |
211+
| `onTaskCreated` | `(task: Task) => boolean \| void` | Return `false` to cancel task creation. |
212+
| `onAfterTaskAdd` | `(id: string \| number, task: Task) => void` | Fires after a task is added. |
213+
| `onAfterTaskUpdate` | `(id: string \| number, task: Task) => void` | Fires after a task is updated. |
214+
| `onAfterTaskDelete` | `(id: string \| number, task: Task) => void` | Fires after a task is deleted. |
215+
| `onAfterLinkAdd` | `(id: string \| number, link: Link) => void` | Fires after a dependency link is added. |
216+
| `onAfterLinkUpdate` | `(id: string \| number, link: Link) => void` | Fires after a dependency link is updated. |
217+
| `onAfterLinkDelete` | `(id: string \| number, link: Link) => void` | Fires after a dependency link is deleted. |
218+
219+
For the full Gantt event list (including events not enumerated above), see the [Gantt events overview](api/overview/events-overview.md). Use `defineGanttEvents(...)` to author the map with autocomplete on these known events.
220+
206221
### `@ready`
207222

208223
`ready(instance)` fires once after initialization and the first sync:
@@ -278,10 +293,6 @@ Replace the built-in task form UI with a Vue component.
278293

279294
Map Gantt inline editor type names to Vue components.
280295

281-
### `templateWrapper`
282-
283-
Wrap VNodes produced by the wrapper template bridge.
284-
285296
### `modals`
286297

287298
Override delete confirmations and call `callback()` to confirm deletion.
@@ -326,10 +337,39 @@ From `@dhtmlx/trial-vue-gantt` or `@dhx/vue-gantt`:
326337

327338
### Type Exports
328339

340+
Import every type from the wrapper package itself (`@dhx/vue-gantt` or `@dhtmlx/trial-vue-gantt`). The wrapper bundles the underlying Gantt engine and re-exports its types alongside the Vue-specific ones - there is no separate `@dhx/gantt` package to install or import from.
341+
342+
**Wrapper-owned types**
343+
329344
| Export | Description |
330345
|--------|------------|
331-
| `SerializedTask` | User-facing task shape with `Date \| string` dates. Use for store state, initial data, and `batchSave` payloads. |
346+
| `SerializedTask` | User-facing task shape with `Date \| string` dates. Use for store state, initial data, and `save`/`batchSave` payloads. |
332347
| `SerializedLink` | User-facing link shape. Use alongside `SerializedTask` in store state and data definitions. |
348+
| `VueGanttRef` | Type of the value exposed via component ref - `{ instance: GanttStatic \| null }`. |
349+
| `VueGanttDataConfig` | Shape of the `data` prop (`load`, `save`, `batchSave`). |
350+
| `BatchChanges` | Argument passed to `data.batchSave` - grouped `tasks`/`links`/`resources`/`resourceAssignments` changes. |
351+
| `DataCallbackChange` | Individual change entry inside a `BatchChanges` bucket - `{ entity, action, data, id }`. |
352+
| `Marker` | Shape of items in the `markers` prop. |
353+
| `WrapperCalendar` | Wrapper-friendly calendar shape accepted by the `calendars` prop (alongside raw `CalendarConfig`). |
354+
| `GanttModals` | Shape of the `modals` prop - `onBeforeTaskDelete` and `onBeforeLinkDelete` callback signatures. |
355+
| `CustomLightboxProps` | Props received by your `customLightbox` component (`data`, `onSave`, `onCancel`, `onDelete`, `ganttInstance`). |
356+
| `InlineEditorComponentProps` | Props received by your inline editor components (`initialValue`, `task`, `save`, `cancel`, `ganttInstance`). |
357+
| `VueGanttEvents` | Type of the `events` prop - known events plus string-keyed custom events. |
358+
359+
**Frequently used types from the Gantt engine**
360+
361+
The wrapper re-exports every type from the underlying Gantt engine. The ones below come up most often in wrapper code - each row maps a core type to where it shows up in the Vue API.
362+
363+
| Export | Where it appears in wrapper code |
364+
|--------|------------|
365+
| `Task`, `Link` | Runtime task/link shapes (include `$`-prefixed properties). Used inside event handlers, template callbacks, and filter functions. |
366+
| `GanttStatic` | Type of `ganttRef.value?.instance` and the `@ready` argument. |
367+
| `GanttConfigOptions` | Shape of the object passed to the `config` prop. |
368+
| `GanttTemplates` | Shape of the object passed to the `templates` prop. |
369+
| `GanttPlugins` | Shape of the object passed to the `plugins` prop. |
370+
| `CalendarConfig` | Raw Gantt calendar shape - alternative to `WrapperCalendar` in the `calendars` prop. |
371+
372+
Every other type from the Gantt engine is also exported from the wrapper - if you can import a name from `@dhx/gantt` in the standalone library, you can import it from `@dhx/vue-gantt` here.
333373

334374
Use `SerializedTask` and `SerializedLink` for data you own (Pinia state, `ref<>`, API responses, initial literals). Use `Task` and `Link` for data gantt owns (inside event handlers, template callbacks, filter functions), where runtime task objects include internal `$`-prefixed properties.
335375

@@ -340,13 +380,42 @@ Use `SerializedTask` and `SerializedLink` for data you own (Pinia state, `ref<>`
340380
- `defineGanttEvents(events)` for typed event map authoring
341381
- `defineInlineEditors(inlineEditors)` for typed inline editor maps
342382

383+
These are **TypeScript-only identity helpers** - at runtime, `defineGanttTemplates(x)` returns `x` unchanged. You can skip them entirely without any behavior change. Their value is **type preservation on object literals**: you get autocomplete on `templates.task_text`, `config.scales[0].unit`, `events.onAfterTaskAdd`, etc., without manually annotating the variable.
384+
385+
If you skip them in TypeScript, either annotate the variable yourself or pass the literal inline on the prop:
386+
387+
~~~ts
388+
// Option 1: explicit type annotation
389+
const templates: Partial<GanttTemplates> = {
390+
task_text: (_s, _e, task) => task.text
391+
};
392+
393+
// Option 2: helper for autocomplete on the literal
394+
const templates = defineGanttTemplates({
395+
task_text: (_s, _e, task) => task.text
396+
});
397+
398+
// Option 3: inline literal - inference works through the prop type
399+
<VueGantt :templates="{ task_text: (_s, _e, task) => task.text }" />
400+
~~~
401+
343402
### Composables
344403

345-
- `useWorkTime(ganttRef)` for work-time checks and date calculations
346-
- `useResourceAssignments(ganttRef)` for task-resource/assignment reads
347-
- `useGanttDatastore(ganttRef, storeName)` for raw datastore access
348-
- `useGanttActions(ganttRef)` for wrapper-safe imperative actions (undo/redo/export/render)
349-
- `useGanttEvent(ganttRef, eventName, handler)` for lifecycle-safe attach/detach of a single event
404+
The wrapper exposes five composables that wrap common instance-side calls in a ref-aware, lifecycle-safe form. Each one takes a `Ref<VueGanttRef | null>` so it can wait for the instance to become available.
405+
406+
#### `useGanttActions(ganttRef)`
407+
408+
Returns wrapper-safe imperative actions:
409+
410+
| Method | Signature | Notes |
411+
|--------|-----------|-------|
412+
| `undo()` | `() => void` | Requires `plugins: { undo: true }`. |
413+
| `redo()` | `() => void` | Requires `plugins: { undo: true }`. |
414+
| `render()` | `() => void` | Forces a redraw - pair with `instance.eachTask(...)` for bulk mutations. |
415+
| `exportToPDF()` | `() => void` | Requires `plugins: { export_api: true }`. |
416+
| `exportToPNG()` | `() => void` | Requires `plugins: { export_api: true }`. |
417+
| `exportToExcel(config?)` | `(config?: object) => void` | Requires `plugins: { export_api: true }`. Pass exporter options through `config`. |
418+
| `exportToMSProject()` | `() => void` | Requires `plugins: { export_api: true }`. |
350419

351420
~~~ts
352421
import { ref } from "vue";
@@ -355,11 +424,89 @@ import { useGanttActions, type VueGanttRef } from "@dhtmlx/trial-vue-gantt";
355424
const ganttRef = ref<VueGanttRef | null>(null);
356425
const actions = useGanttActions(ganttRef);
357426

358-
function exportPdf() {
359-
actions.exportToPDF();
360-
}
427+
const exportPdf = () => actions.exportToPDF();
428+
const exportExcel = () => actions.exportToExcel({ visual: "base-colors" });
361429
~~~
362430

431+
#### `useWorkTime(ganttRef)`
432+
433+
Returns a computed wrapper around the Gantt work-time API. Useful in templates and constraint calculations.
434+
435+
| Method | Signature |
436+
|--------|-----------|
437+
| `isWorkTime({ date, task?, unit? })` | `(args) => boolean` |
438+
| `calculateEndDate({ start, duration, unit?, task? })` | `(args) => Date` |
439+
| `calculateDuration({ start, end, task? })` | `(args) => number` |
440+
| `getClosestWorkTime({ date, task?, unit, dir? })` | `(args) => Date` |
441+
442+
~~~ts
443+
import { useWorkTime, type VueGanttRef } from "@dhtmlx/trial-vue-gantt";
444+
445+
const ganttRef = ref<VueGanttRef | null>(null);
446+
const workTime = useWorkTime(ganttRef);
447+
448+
const templates = {
449+
scale_cell_class: (date: Date) =>
450+
workTime.value.isWorkTime({ date }) ? "" : "weekend"
451+
};
452+
~~~
453+
454+
#### `useGanttDatastore<T>(ganttRef, storeName)`
455+
456+
Returns a computed reader for any Gantt datastore (for example `"task"`, `"link"`, `"resource"`).
457+
458+
| Method | Signature |
459+
|--------|-----------|
460+
| `getItem(id)` | `(id: string \| number) => T \| null` |
461+
| `getItems()` | `() => T[]` |
462+
| `hasChild(id)` | `(id: string \| number) => boolean` |
463+
| `getChildren(id)` | `(id: string \| number) => (string \| number)[]` |
464+
465+
~~~ts
466+
import type { Task } from "@dhtmlx/trial-vue-gantt";
467+
import { useGanttDatastore } from "@dhtmlx/trial-vue-gantt";
468+
469+
const taskStore = useGanttDatastore<Task>(ganttRef, "task");
470+
471+
const rootTasks = computed(() => taskStore.value.getChildren(0));
472+
~~~
473+
474+
#### `useResourceAssignments(ganttRef)`
475+
476+
Returns a computed reader for resource/task assignment data.
477+
478+
| Method | Signature |
479+
|--------|-----------|
480+
| `getResourceAssignments(resourceId, taskId?)` | `(resourceId: string \| number, taskId?: string \| number) => any[]` |
481+
| `getTaskResources(taskId)` | `(taskId: string \| number) => any[]` |
482+
483+
~~~ts
484+
import { useResourceAssignments } from "@dhtmlx/trial-vue-gantt";
485+
486+
const assignments = useResourceAssignments(ganttRef);
487+
488+
const showAssignments = (resourceId: string | number) => {
489+
console.log(assignments.value.getResourceAssignments(resourceId));
490+
};
491+
~~~
492+
493+
#### `useGanttEvent(ganttRef, eventName, handler)`
494+
495+
Attaches a single Gantt event with a lifecycle-safe lifetime. The handler is detached automatically on component unmount and re-attached if `ganttRef`, `eventName`, or `handler` change. Returns `{ detach }` for manual control.
496+
497+
~~~ts
498+
import { useGanttEvent } from "@dhtmlx/trial-vue-gantt";
499+
500+
const { detach } = useGanttEvent(ganttRef, "onTaskDblClick", id => {
501+
console.log("dbl-click", id);
502+
});
503+
504+
// Optional: detach early
505+
// detach();
506+
~~~
507+
508+
Use this when one-off listeners do not fit cleanly into the `events` map (for example listeners that need to update or unsubscribe based on local state).
509+
363510
## What To Read Next
364511

365512
- [Vue Gantt Overview](integrations/vue/overview.md)

0 commit comments

Comments
 (0)