Dynamic data loading and the resource view

I’ve got a quite complicated system to calculate the resource load, which does not allow me to have all the info in memory at once. So what I would like to do is, as I switch to a more fine grained view (month -> day) to dynamically load the newly needed data.

I can kick off the AJAX request when I press the button to toggle the view mode. However the view mode is fully changed before my AJAX request completes and thus when the resource diagramm is drawn and my resource_cell_{class|value} get called I do not have the data ready.

Is there a way to either:

  • delay the drawing until a condition is met (maybe show a nice spinner instead) or
  • force the gantt to repaint the resource diagramm?

There is “onBeforeDataRender” event, but unfortunately it doesn’t depend on returning values (like some other functions allow canceling the event).
But before rendering you can show an overlay and a nice spinner. Then you use a delayed function that will always check the condition. Here is an example how it might be implemented:

To repaint the whole chart you can try “gantt.render()” function or even gantt.init() function if there is something related to templates or something else.

Probably, the best way is to show a loading animation, then call the Gantt methods that trigger the data repaint.
Here is an example of how it can be implemented:

Also, if you need to repaint only the resource panel, you can call the refresh method from the resource datastore object: