Sort Gantt tasks by start date on initial load raises error

I am trying to use the standard edition Gantt version 5.1.0 in a project. On initial load I would like to have the tasks sorted by start date. But when I include the following line:
gantt.sort(“start_date”, true);
I get an error in the browser console as follows:
Uncaught TypeError: t._getVerticalScrollbar is not a function
at n.t._scroll_state (dhtmlxgantt.js:10)
at n.t.getScrollState (dhtmlxgantt.js:10)
at n.t.render (dhtmlxgantt.js:10)
at n.sort (dhtmlxgantt.js:10)
at dhtmlxgantt.html:17

I have also enabled the feature to click on a specific column header to sort by that column. That functionality works if I remove the gantt.sort line from the javascript code.
Following is the code that reproduces the problem.

You get the error because Gantt is not initialized and the tasks are not loaded yet when you try to sort the tasks. If you add it after tasks were parsed, Gantt will sort them correctly:
I changed the option from true to false because tasks are already sorted in descending order in the tasks variable. So after parsing tasks Gantt will sort them in ascending order.

1 Like