Please use task_class template to specify the CSS class that will be applied to task bars with children to hide them
and getChildren method to check if the target task has got the 1st-level child tasks:
gantt.templates.task_class = function(start, end, task){
var children = gantt.getChildren(task.id);
if(children.length)
return "hideTask";
return "";
};
CSS:
.hideTask{visibility: hidden;}