@@ -33,13 +33,45 @@ import App from "./App.vue";
3333createApp (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
3869Create ` src/stores/ganttStore.ts ` :
3970
4071~~~ ts title="src/stores/ganttStore.ts"
4172import { defineStore } from " pinia" ;
4273import type { BatchChanges , SerializedLink , SerializedTask } from " @dhtmlx/trial-vue-gantt" ;
74+ import { links , tasks } from " ../demoData" ;
4375
4476type ZoomLevel = " day" | " month" | " year" ;
4577
@@ -96,8 +128,8 @@ function applyBatchChanges(tasks: SerializedTask[], links: SerializedLink[], cha
96128
97129export 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">
136168import { storeToRefs } from "pinia";
137- import VueGantt from "@dhtmlx/trial-vue-gantt";
169+ import VueGantt, { type BatchChanges } from "@dhtmlx/trial-vue-gantt";
138170import "@dhtmlx/trial-vue-gantt/dist/vue-gantt.css";
139171
140172import { useGanttStore } from "../stores/ganttStore";
@@ -143,7 +175,7 @@ const store = useGanttStore();
143175const { tasks, links, config, zoomLevel } = storeToRefs(store);
144176
145177const data = {
146- batchSave: changes => store.applyBatch(changes)
178+ batchSave: ( changes: BatchChanges) => store.applyBatch(changes)
147179};
148180
149181const 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
177225Use this flow for predictable updates:
178226
@@ -184,20 +232,21 @@ Use this flow for predictable updates:
184232
185233Do 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
189237Use this if you want undo/redo while keeping Pinia as the source of truth.
190238
191239Do 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
195243Replace the store from step 2 with this version.
196244It keeps state typed as ` SerializedTask[] ` / ` SerializedLink[] ` and avoids ` as any ` casts in date cloning.
197245
198246~~~ ts title="src/stores/ganttStore.ts"
199247import { defineStore } from " pinia" ;
200248import type { BatchChanges , SerializedLink , SerializedTask } from " @dhtmlx/trial-vue-gantt" ;
249+ import { links , tasks } from " ../demoData" ;
201250
202251type ZoomLevel = " day" | " month" | " year" ;
203252
@@ -289,8 +338,8 @@ const createSnapshot = (state: HistoryState): Snapshot => ({
289338
290339export 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">
369418import { storeToRefs } from "pinia";
370- import VueGantt from "@dhtmlx/trial-vue-gantt";
419+ import VueGantt, { type BatchChanges } from "@dhtmlx/trial-vue-gantt";
371420import "@dhtmlx/trial-vue-gantt/dist/vue-gantt.css";
372421
373422import { useGanttStore } from "../stores/ganttStore";
@@ -376,7 +425,7 @@ const store = useGanttStore();
376425const { tasks, links, config, zoomLevel, canUndo, canRedo } = storeToRefs(store);
377426
378427const data = {
379- batchSave: changes => store.applyBatch(changes)
428+ batchSave: ( changes: BatchChanges) => store.applyBatch(changes)
380429};
381430
382431const 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
406455Use 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