Skip to content

Commit e5105dd

Browse files
author
alex
committed
Merge pull request '[update] 'parse' article' (#98) from GS-2847 into master
Reviewed-on: https://git.webix.io/Servers/gantt-docs/pulls/98
2 parents 26ba972 + 616427d commit e5105dd

File tree

1 file changed

+97
-115
lines changed

1 file changed

+97
-115
lines changed

data/api/gantt_parse.md

Lines changed: 97 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ parse
1010

1111
@example:
1212
gantt.parse({
13-
data:[
14-
{id:1, text:"Project #2", start_date:"01-04-2023", duration:18},
15-
{id:2, text:"Task #1", start_date:"02-04-2023", duration:8,
16-
progress:0.6, parent:1},
17-
{id:3, text:"Task #2", start_date:"11-04-2023", duration:8,
18-
progress:0.6, parent:1}
19-
],
20-
links:[
21-
{ id:1, source:1, target:2, type:1},
22-
{ id:2, source:2, target:3, type:0}
23-
]
13+
tasks: [
14+
{ id: 1, text: "Project #2", start_date: "01-04-2026", duration: 18 },
15+
{ id: 2, text: "Task #1", start_date: "02-04-2026", duration: 8, progress: 0.6,
16+
parent: 1 },
17+
{ id: 3, text: "Task #2", start_date: "11-04-2026", duration: 8, progress: 0.6,
18+
parent: 1 }
19+
],
20+
links: [
21+
{ id: 1, source: 1, target: 2, type: 1 },
22+
{ id: 2, source: 2, target: 3, type: 0 }
23+
]
2424
});
2525

2626
@template: api_method
@@ -33,45 +33,42 @@ gantt.parse({
3333
desktop/supported_data_formats.md
3434
desktop/supported_data_formats.md#jsonwithcollections (read how to load JSON with Collections)
3535
@descr:
36-
Gantt expects that *an array with tasks* will be named either **data** or **tasks** whereas *an array with links* will be named **links**.
36+
Gantt expects that *an array with tasks* will be named either **tasks** or **data** whereas *an array with links* will be named **links**.
3737

3838
This is the list of expected properties:
3939

40-
- <span class=subproperty>**data**</span> - (*[] | NewTask[]*) - the array with the task data
40+
- <span class=subproperty>**tasks**</span> - (*[] | NewTask[]*) - the array with the task data
4141
- <span class=subproperty>**links?**</span> - (*Link[]*) - the array with the link data
4242
- <span class=subproperty>**resources?**</span> - (*NewResourceItem[]*) - the array with the resource data
4343
- <span class=subproperty>**assignments?**</span> - (*NewAssignmentItem[]*) - the array with the assignment data
44-
- <span class=subproperty>**collections?**</span> - (*Сollections*) - the object that has the arrays with the custom data
44+
- <span class=subproperty>**collections?**</span> - (*Collections*) - the object that has the arrays with the custom data
4545

4646
~~~js
4747
gantt.parse({
48-
data: [
49-
{ id: 1, start_date: "2025-09-23", duration: 42,
50-
text: "House Construction" },
51-
{ id: 2, start_date: "2025-12-02", duration: 60,
52-
text: "House Construction" },
53-
],
54-
"links": [
55-
{ id: "1", source: "1", target: "2", type: "0" },
56-
],
57-
"resources": [
58-
{ id: 1, text: "Anna, Architect", unit: "hours/day",
59-
default_value: 8, type: "work" },
60-
],
61-
"assignments": [
62-
{ task_id: "1", resource_id: "1", value: "8" },
63-
{ task_id: "2", resource_id: "1", value: "8",
64-
mode: "fixedDates", start_date: "2025-09-23",
65-
end_date: "2025-09-25", duration: 4, delay: 2, },
66-
{ task_id: "2", resource_id: "1", value: "8",
67-
start_date: new Date("2025-09-23 00:00:00"),
68-
end_date: new Date("2025-09-26 00:00:00"), },
69-
]
70-
})
48+
tasks: [
49+
{ id: 1, start_date: "2026-09-23", duration: 42, text: "House Construction" },
50+
{ id: 2, start_date: "2026-12-02", duration: 60, text: "House Construction" }
51+
],
52+
links: [
53+
{ id: 1, source: 1, target: 2, type: 0 }
54+
],
55+
resources: [
56+
{ id: 1, text: "Anna, Architect", unit: "hours/day", default_value: 8,
57+
type: "work" }
58+
],
59+
assignments: [
60+
{ task_id: 1, resource_id: 1, value: "8" },
61+
{ task_id: 2, resource_id: 1, value: "8", mode: "fixedDates",
62+
start_date: "2026-09-23", end_date: "2026-09-25", duration: 4, delay: 2 },
63+
{ task_id: 2, resource_id: 1, value: "8",
64+
start_date: new Date("2026-09-23T00:00:00"),
65+
end_date: new Date("2026-09-26T00:00:00") }
66+
]
67+
});
7168
~~~
7269

7370

74-
The **data** or **tasks** array expects the **NewTask** object that is different from the **Task** object. It can be a string, an empty object.
71+
The **tasks** or **data** array expects the **NewTask** object that is different from the **Task** object. It can be a string, an empty object.
7572
It can have the same properties as the [**Task** object](desktop/task_properties.md), and you can add any custom properties there.
7673
The difference is that some properties of the **Task** object that start from the *$* sign are ignored and the dates can have the *string* type.
7774
Here is the type description:
@@ -91,28 +88,24 @@ This is not the full list of possible task properties. For that, please refer to
9188

9289
~~~js
9390
gantt.parse({
94-
data: [
95-
{ id: 1, start_date: "2025-09-23", duration: 42,
96-
text: "House Construction" },
97-
]
91+
tasks: [
92+
{ id: 1, text: "House Construction", start_date: "2026-09-23", duration: 42 },
93+
]
9894
})
9995
~~~
100-
101-
10296
---
10397

10498

10599
The **links** array expects the [**Link** objects](desktop/link_properties.md).
106100

107101
~~~js
108102
gantt.parse({
109-
data: [],
110-
links: [
111-
{ id: "1", source: "1", target: "2", type: "0" },
112-
]
103+
tasks: [],
104+
links: [
105+
{ id: "1", source: "1", target: "2", type: "0" },
106+
]
113107
})
114108
~~~
115-
116109
---
117110

118111

@@ -129,15 +122,13 @@ The **resources** array expects the **NewResourceItem** object that may have the
129122

130123
~~~js
131124
gantt.parse({
132-
data: [],
133-
resources: [
134-
{ id: 1, text: "Anna, Architect", unit: "hours/day",
135-
default_value: 8, type: "work" },
136-
]
125+
tasks: [],
126+
resources: [
127+
{ id: 1, text: "Anna, Architect", unit: "hours/day", default_value: 8,
128+
type: "work" },
129+
]
137130
})
138131
~~~
139-
140-
141132
---
142133

143134

@@ -158,59 +149,54 @@ The **assignments** array expects the **NewAssignmentItem** object that may have
158149

159150
~~~js
160151
gantt.parse({
161-
data: [],
162-
assignments: [
163-
{ task_id: "1", resource_id: "1", value: "8" },
164-
]
152+
tasks: [],
153+
assignments: [
154+
{ task_id: "1", resource_id: "1", value: "8" },
155+
]
165156
})
166157
~~~
167-
168158
---
169159

160+
170161
The **collections** object allows loading any custom data. The properties can have any name, and the value should be an array that contains the collection items:
171162

172-
- <span class=subproperty>**[collectionName: string]**</span> - (*[] | СollectionItem[]*) - an array that contains the collection items.
163+
- <span class=subproperty>**[collectionName: string]**</span> - (*[] | CollectionItem[]*) - an array that contains the collection items.
173164

174-
The **СollectionItem** is an object that can have any properties. It has the following types for its properties:
165+
The **CollectionItem** is an object that can have any properties. It has the following types for its properties:
175166

176167
- <span class=subproperty>**[itemProperty: string]**</span> - (*any*) - any custom property of the collection item.
177168

178169

179170
~~~js
180171
gantt.parse({
181-
data: [
182-
{ "id": "1", "text": "Task #1", "priority": 1,
183-
"start_date": "02-04-2019", "duration": 1, },
184-
{ "id": "2", "text": "Task #2", "priority": 2,
185-
"start_date": "01-04-2019", "duration": 1, },
186-
{ "id": "3", "text": "Task #3", "priority": 3,
187-
"start_date": "02-04-2019", "duration": 1, },
188-
{ "id": "4", "text": "Task #4", "priority": 1,
189-
"start_date": "03-04-2019", "duration": 1, },
190-
],
191-
links: [],
192-
collections: {
193-
task_priority: [
194-
{ key: 1, label: "High" },
195-
{ key: 2, label: "Normal" },
196-
{ key: 3, label: "Low" }
197-
]
198-
}
172+
tasks: [
173+
{ id: "1", text: "Task #1", priority: 1, start_date: "02-04-2026", duration:1 },
174+
{ id: "2", text: "Task #2", priority: 2, start_date: "01-04-2026", duration:1 },
175+
{ id: "3", text: "Task #3", priority: 3, start_date: "02-04-2026", duration:1 },
176+
{ id: "4", text: "Task #4", priority: 1, start_date: "03-04-2026", duration:1 }
177+
],
178+
links: [],
179+
collections: {
180+
task_priority: [
181+
{ key: 1, label: "High" },
182+
{ key: 2, label: "Normal" },
183+
{ key: 3, label: "Low" }
184+
]
185+
}
199186
});
200187
~~~
201-
202188
---
203189

204190

205191
If you want to load data which doesn't contain tasks, you still need to define an array of tasks in the object with data but it can be empty:
206192

207193
~~~js
208194
gantt.parse({
209-
tasks:[],
210-
links:[
211-
{ id:1, source:1, target:2, type:1},
212-
{ id:2, source:2, target:3, type:0}
213-
]
195+
tasks: [],
196+
links: [
197+
{ id: 1, source: 1, target: 2, type: 1 },
198+
{ id: 2, source: 2, target: 3, type: 0 }
199+
]
214200
});
215201
~~~
216202

@@ -219,34 +205,30 @@ From v8.0, besides tasks and links, you can load resources and resource assignme
219205

220206
~~~js
221207
gantt.parse({
222-
tasks: [
223-
...,
224-
{
225-
id: 5,
226-
text: "Interior office",
227-
type: "task",
228-
start_date: "03-04-2024 00:00",
229-
duration: 7,
230-
parent: "2",
231-
owner: [
232-
{
233-
resource_id: "6",
234-
value: 3,
235-
start_date: "03-04-2024 00:00",
236-
end_date: "05-04-2024 00:00",
237-
}
238-
]
239-
},
240-
...
241-
],
242-
links: [],
243-
resources: [
244-
{id: 6, text: "John", unit: "hours/day" },
245-
{id: 7, text: "Mike", unit: "hours/day" },
246-
{id: 8, text: "Anna", unit: "hours/day" },
247-
{id: 9, text: "Bill", unit: "hours/day" },
248-
{id: 10, text: "Floe", unit: "hours/day" }
249-
]
208+
tasks: [
209+
// ...
210+
{
211+
id: 5,
212+
text: "Interior office",
213+
type: "task",
214+
start_date: "03-04-2026 00:00",
215+
duration: 7,
216+
parent: "2",
217+
owner: [
218+
{ resource_id: "6", value: 3, start_date: "03-04-2026 00:00",
219+
end_date: "05-04-2026 00:00" }
220+
]
221+
},
222+
// ...
223+
],
224+
links: [],
225+
resources: [
226+
{ id: 6, text: "John", unit: "hours/day" },
227+
{ id: 7, text: "Mike", unit: "hours/day" },
228+
{ id: 8, text: "Anna", unit: "hours/day" },
229+
{ id: 9, text: "Bill", unit: "hours/day" },
230+
{ id: 10, text: "Floe", unit: "hours/day" }
231+
]
250232
});
251233
~~~
252234

0 commit comments

Comments
 (0)