Scroll Gantt Chart to Today

Is there a way to programatically scroll a Gantt Chart horizontally to today’s date? Any help would be appreciated. Thank you.

Eric

Use this code after create():

ganttChartControl.oData.scrollLeft = ((new Date() - ganttChartControl.startDate) / (24*60*60000) - 10) * ganttChartControl.dayInPixels;
Here I additionally subtract 10 (days) so that today is not exactly at the very left side, but a bit off to the right (looks nicer). You can also remove this “- 10”.

Thanks for the quick reply. Works great!

Hi, I see you mention a ‘create()’ function. I am trying to do the same, to scroll to ‘today’ and other dates.

However, I get the error: ‘ganttChartControl is not defined’. I take it my problem lies with my lack of a create() function. I could not find the correct documentation on ‘ganttChartControl’.

What am I missing and where can I find it? Thank you in advance :slight_smile:

Hi,
in recent versions of the dhtmlxGantt (v2.0+), you can use this method
docs.dhtmlx.com/gantt/api__gantt_showdate.html

1 Like

Thanks a million! Was exactly what I was looking for! And thanks for such an amazing array of products :slight_smile: