serialize()
Description
Exports the current diagram data
Usage
serialize(): object[] | { data: object[]; links: object[] };
Returns
Depending on the diagram mode, the method returns:
object[]- (for the default, org chart and mindmap Diagram modes) an array of objects for each item and link from Diagram{ data: object[]; links: object[] }- (for the PERT Diagram mode) an object with:- the
dataarray of objects (for shapes: "task", "milestone", "project") - the
linksarray of objects (for connections between shapes)
- the
Example
- for the default diagram mode
const diagram = new dhx.Diagram("diagram_container", {
type: "default"
});
diagram.data.parse(data);
const data = diagram.data.serialize(); // -> [{...}, {...}, {...}, {...}]
- for the PERT diagram mode
const diagram = new dhx.Diagram("diagram_container", {
type: "pert"
});
diagram.data.parse(dataset);
const dataset = diagram.data.serialize(); // -> { data: [...], links: [...] };
Note that for the PERT Diagram mode the links objects in the exported data object will have the same types as in the DHTMLX Gantt chart. It means that if the type of a link in the Diagram data coincides with some of the Gantt links types, it will remain the same during serialization. If the link type isn't specified or set differently (for example, type: "line"), it will be converted into type: "0".
Related articles: Saving and restoring state