Is gantt.render() needed here?

Hello! I have a js parsing function AttachedEvent(‘Parse’, onParse)

onParse => {
   gantt.eachTask((task: GanttTask) => {...}
   gantt.render()
}

onParse internally iterates through all the tasks and for each task calls a function within which, depending on the condition, we do the following

if (type === TaskType.Project && !gantt.hasChild(id)) {
   gantt.silent(() => {
      fillerId = gantt.addTask(...)
   })

   if (fillerId) {
      gantt.getTask(fillerId).start_date = new Date(start_date)
      gantt.getTask(fillerId).end_date = endDate
      gantt.updateTask(fillerId)
   }
   gantt.render()
}

The question is, do we need to call gantt.render() for each task inside the loop if we still call gantt.render() after the loop ends? This causes some problems when parsing. If you remove gantt.render() for each task inside the loop, there is no problem

P.S. I didn’t write this code, I’m trying to figure it out :smiley:

Hello Viktor,
If you call the render method too often, it will affect performance. It is enough to repaint the data once after the eachTask method.
Also, there is no need to add the task dates right after adding the task. You can specify the dates inside the addTask method, and you won’t need to update the task.

Here is an example in the snippet.
https://snippet.dhtmlx.com/yzmqinhm

If you really need to use the code exactly as it is written, you can put it inside the batchUpdate method, then Gantt will repaint the changes only once:
https://docs.dhtmlx.com/gantt/api__gantt_batchupdate.html

1 Like