Skip to content

Commit da6ee7e

Browse files
Merge pull request #93 from AlexKlimenkov/master
Update Vue Gantt guides
2 parents 2b6ff0f + 2427910 commit da6ee7e

2 files changed

Lines changed: 78 additions & 26 deletions

File tree

docs/integrations/vue/quick-start.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ description: "Step-by-step guide to render the official Vue Gantt wrapper in a V
88

99
Use this quick start to render Vue Gantt in a Vue 3 + Vite app with a dedicated Gantt component and `data.save` callback wiring.
1010

11+
If you're new to Vue, start with the official [Vue documentation](https://vuejs.org/guide/introduction.html). Check [a complete working project that follows this tutorial on GitHub](https://github.com/DHTMLX/vue-gantt-quick-start).
12+
1113
## Prerequisites
1214

1315
- Node.js installed
@@ -162,6 +164,12 @@ You now have a Vue 3 app rendering the official Vue Gantt wrapper with:
162164
- wrapper CSS imported
163165
- `data.save` callback wiring for user edits
164166

167+
This is the same minimal example used in the [GitHub demo project](https://github.com/DHTMLX/vue-gantt-quick-start).
168+
169+
## GitHub demo repository
170+
171+
A complete working project that follows this tutorial is [provided on GitHub](https://github.com/DHTMLX/vue-gantt-quick-start).
172+
165173
## What To Read Next
166174

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

docs/integrations/vue/state/pinia.md

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,45 @@ import App from "./App.vue";
3333
createApp(App).use(createPinia()).mount("#app");
3434
~~~
3535

36-
## 2. Create A Basic Gantt Store
36+
## 2. Add Demo Data
37+
38+
Create `src/demoData.ts`:
39+
40+
~~~ts title="src/demoData.ts"
41+
import type { SerializedLink, SerializedTask } from "@dhtmlx/trial-vue-gantt";
42+
43+
export const tasks: SerializedTask[] = [
44+
{
45+
id: 1,
46+
text: "Office itinerancy",
47+
type: "project",
48+
start_date: new Date(2026, 0, 5),
49+
duration: 10,
50+
progress: 0.4,
51+
open: true,
52+
parent: 0
53+
},
54+
{
55+
id: 2,
56+
text: "Planning",
57+
start_date: new Date(2026, 0, 5),
58+
duration: 4,
59+
progress: 0.6,
60+
parent: 1
61+
}
62+
];
63+
64+
export const links: SerializedLink[] = [{ id: 1, source: 1, target: 2, type: "0" }];
65+
~~~
66+
67+
## 3. Create A Basic Gantt Store
3768

3869
Create `src/stores/ganttStore.ts`:
3970

4071
~~~ts title="src/stores/ganttStore.ts"
4172
import { defineStore } from "pinia";
4273
import type { BatchChanges, SerializedLink, SerializedTask } from "@dhtmlx/trial-vue-gantt";
74+
import { links, tasks } from "../demoData";
4375

4476
type ZoomLevel = "day" | "month" | "year";
4577

@@ -96,8 +128,8 @@ function applyBatchChanges(tasks: SerializedTask[], links: SerializedLink[], cha
96128

97129
export const useGanttStore = defineStore("gantt", {
98130
state: () => ({
99-
tasks: [] as SerializedTask[],
100-
links: [] as SerializedLink[],
131+
tasks: tasks,
132+
links: links,
101133
zoomLevel: "day" as ZoomLevel
102134
}),
103135
getters: {
@@ -127,14 +159,14 @@ This store keeps one source of truth:
127159
- `config` is derived state
128160
- `applyBatch` is the wrapper callback entry point
129161

130-
## 3. Bind Store State To `VueGantt`
162+
## 4. Bind Store State To `VueGantt`
131163

132-
Create `src/components/GanttBoard.vue`:
164+
Create `src/components/GanttChart.vue`:
133165

134-
~~~vue title="src/components/GanttBoard.vue"
166+
~~~vue title="src/components/GanttChart.vue"
135167
<script setup lang="ts">
136168
import { storeToRefs } from "pinia";
137-
import VueGantt from "@dhtmlx/trial-vue-gantt";
169+
import VueGantt, { type BatchChanges } from "@dhtmlx/trial-vue-gantt";
138170
import "@dhtmlx/trial-vue-gantt/dist/vue-gantt.css";
139171
140172
import { useGanttStore } from "../stores/ganttStore";
@@ -143,7 +175,7 @@ const store = useGanttStore();
143175
const { tasks, links, config, zoomLevel } = storeToRefs(store);
144176
145177
const data = {
146-
batchSave: changes => store.applyBatch(changes)
178+
batchSave: (changes: BatchChanges) => store.applyBatch(changes)
147179
};
148180
149181
const setZoom = (level: "day" | "month" | "year") => {
@@ -172,7 +204,23 @@ This is the core wrapper wiring:
172204
- `batchSave` -> store action
173205
- store action -> new state -> wrapper props again
174206

175-
## 4. Verify The Data Flow
207+
## 5. Render Gantt In The App Shell
208+
209+
Replace `src/App.vue`:
210+
211+
~~~vue title="src/App.vue"
212+
<script setup lang="ts">
213+
import GanttChart from "./components/GanttChart.vue";
214+
</script>
215+
216+
<template>
217+
<div :style="{ height: '100%', width: '100%' }">
218+
<GanttChart />
219+
</div>
220+
</template>
221+
~~~
222+
223+
## 6. Verify The Data Flow
176224

177225
Use this flow for predictable updates:
178226

@@ -184,20 +232,21 @@ Use this flow for predictable updates:
184232

185233
Do not mix this with direct instance mutations unless you also update the store.
186234

187-
## 5. (Optional) Add Store-Level Undo/Redo
235+
## 7. (Optional) Add Store-Level Undo/Redo
188236

189237
Use this if you want undo/redo while keeping Pinia as the source of truth.
190238

191239
Do not enable `gantt.plugins({ undo: true })` in this mode.
192240

193-
### 5.1 Replace The Store With A History Version
241+
### 7.1 Replace The Store With A History Version
194242

195243
Replace the store from step 2 with this version.
196244
It keeps state typed as `SerializedTask[]` / `SerializedLink[]` and avoids `as any` casts in date cloning.
197245

198246
~~~ts title="src/stores/ganttStore.ts"
199247
import { defineStore } from "pinia";
200248
import type { BatchChanges, SerializedLink, SerializedTask } from "@dhtmlx/trial-vue-gantt";
249+
import { links, tasks } from "../demoData";
201250

202251
type ZoomLevel = "day" | "month" | "year";
203252

@@ -289,8 +338,8 @@ const createSnapshot = (state: HistoryState): Snapshot => ({
289338

290339
export const useGanttStore = defineStore("gantt", {
291340
state: () => ({
292-
tasks: [] as SerializedTask[],
293-
links: [] as SerializedLink[],
341+
tasks: tasks,
342+
links: links,
294343
zoomLevel: "day" as ZoomLevel,
295344
past: [] as Snapshot[],
296345
future: [] as Snapshot[],
@@ -360,14 +409,14 @@ export const useGanttStore = defineStore("gantt", {
360409
});
361410
~~~
362411

363-
### 5.2 Add Undo/Redo Buttons To The Component
412+
### 7.2 Add Undo/Redo Buttons To The Component
364413

365-
Update `src/components/GanttBoard.vue`:
414+
Update `src/components/GanttChart.vue`:
366415

367-
~~~vue title="src/components/GanttBoard.vue"
416+
~~~vue title="src/components/GanttChart.vue"
368417
<script setup lang="ts">
369418
import { storeToRefs } from "pinia";
370-
import VueGantt from "@dhtmlx/trial-vue-gantt";
419+
import VueGantt, { type BatchChanges } from "@dhtmlx/trial-vue-gantt";
371420
import "@dhtmlx/trial-vue-gantt/dist/vue-gantt.css";
372421
373422
import { useGanttStore } from "../stores/ganttStore";
@@ -376,7 +425,7 @@ const store = useGanttStore();
376425
const { tasks, links, config, zoomLevel, canUndo, canRedo } = storeToRefs(store);
377426
378427
const data = {
379-
batchSave: changes => store.applyBatch(changes)
428+
batchSave: (changes: BatchChanges) => store.applyBatch(changes)
380429
};
381430
382431
const setZoom = (level: "day" | "month" | "year") => {
@@ -401,7 +450,7 @@ const setZoom = (level: "day" | "month" | "year") => {
401450
</template>
402451
~~~
403452

404-
### 5.3 Why This Uses Store-Level History
453+
### 7.3 Why This Uses Store-Level History
405454

406455
Use store-level history here because the store is the source of truth:
407456

@@ -426,14 +475,9 @@ You now have a Pinia-based integration where:
426475
- Mixing store ownership with direct instance mutations and not reconciling state
427476
- Enabling the built-in Gantt undo plugin together with store-level history
428477

429-
## Alignment With Public Sample
430-
431-
This tutorial matches the same store-driven approach used in:
478+
## GitHub demo repository
432479

433-
- `vue/samples-public/src/stores/ganttStore.ts`
434-
- `vue/samples-public/src/examples/state-management/Demo.vue`
435-
- `vue/tests/cypress/e2e/public/007-state-management.cy.ts`
436-
- `vue/samples-public/src/examples/shared/useDemoBatchState.ts`
480+
A complete working project that follows this tutorial is [provided on GitHub](https://github.com/DHTMLX/vue-gantt-pinia-starter).
437481

438482
## What To Read Next
439483

0 commit comments

Comments
 (0)