Based on answers in my 2 earlier posts, I know understand that this in fact a bug.
- Problems with duration and end date - how to re-trigger end_date calculation - Gantt - DHTMLX
- Difference between task.open and task.$open - Gantt - DHTMLX
The open and $open property should be synchronized. As a workaround, I do something like
this._gantt.attachEvent(Gantt.DHTMLX_EVENTS.ON_TASK_OPENED, (id) => {
const task = gantt.getTask(id);
task.open = task.$open;
this._bufferEvent({id: id, type: Gantt.AGNICO_EVENTS.TASK_UPDATED, task: this.createShallowCopy(gantt.getTask(id))});
});
<!DOCTYPE html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Basic initialization</title>
<script src="../../codebase/dhtmlxgantt.js?v=9.0.13"></script>
<link rel="stylesheet" href="../../codebase/dhtmlxgantt.css?v=9.0.13">
<style>
html,
body {
height: 100%;
padding: 0px;
margin: 0px;
overflow: hidden;
}
</style>
</head>
<body>
<div id="gantt_here" style='width:100%; height:50%;'></div>
<div style="height: 100px;">
<button onclick="sayStatus()">click here to show the open and $open status</button>
</div>
<textarea id="txt" rows="100" cols="200"></textarea>
<script>
gantt.init("gantt_here");
let model = {
tasks: [
{ id: 1, text: "Project A", type: "project", open: true },
{ id: 11, text: "Task #A1", start_date: "03-04-2023", duration: 5, parent: 1, open: true },
{ id: 12, text: "Task #A2", start_date: "03-04-2023", type: "project", parent: 1, open: true },
]
};
gantt.parse(model);
function sayStatus() {
let task = gantt.getTask(1);
document.getElementById("txt").value += `The task is now open ${task.open} $open ${task.$open}.\n`;
}
</script>
</body>