Task class apply after task selection only

Hi ,
I have added gantt.templates.task_class ,but it works only after task selection. following is code:

gantt.templates.task_class = function (s, e, task) {

          if (task.progress < 1 && task.end_date < new Date()) {
                return 'gantt_exceeded';

            return '';

how to apply it on load it self?

You can add that function before gantt.init() function. Here is an example: