Hello Joseph,
Why was it that when I clicked on addTask (+) button, and save it, it will trigger onBeforeDataRender to run twice? [when lightbox opened, it will trigger once]
When you click on the “Add” button, Gantt creates a new task with the addTask
command, that creates a temporary task with some predefined parameters. That command requires repainting the changes.
If you click on the “Cancel” or “Delete” buttons, then the task will be deleted.
If you click on the “Save” button, there is the following sequence of events:
- Gantt saves the changes to an object.
- Gantt checks if it is a new task.
• If it is a new task, Gantt removes the $new
property. After that, Gantt uses the addTask
command to create a task. As the IDs of the temporary task and the new task match, the temporary task will be replaced. But it requires repainting the changes.
• If the task is not “new”, Gantt updates the properties of the task and then updates the task.
3) Gantt uses the refreshData()
to repaint the changes.
As you see, repainting happens 2 times for new tasks.
I have this simple example - http://snippet.dhtmlx.com/810b24916
I used onBeforeGanttRender to loop through all tasks, and update some stuff before I paint on the screen. But it seem to me that it will paint on the screen, update it, and repaint it again as you can see that it is obvious that the charts moved right after it first got painted. Is that supposed to be the behavior?
The order of the commands is important for Gantt. In the snippet, you attach the event after the tasks are loaded, so, it will update tasks only after the data is repainted. And another thing is that it will happen every time when the data is rendered if you use the onBeforeDataRender
event handler.
update all fields to the correct state before passing to gantt.parse() so that it can render correctly on initial parse
Is that right?
Yes, for better performance, you can update the data before it is displayed. You can update the JSON variable before parsing it with the gantt.parse()
command to make sure that all the data is changed.
Or you can change the data in the onParse
event handler, but you need to put it before the gantt.parse
command.
P.S is there a difference calling batchUpdate inside of onBeforeDataRender?
If you use the batchUpdate
function, you will get more repaintings and more events will fire because of that.