How can i check if Gantt is grouped?

How can i check if the groupBy function has been called and the Gantt is currently grouped?

Hello,
Unfortunately, there is no such handler. However, you can add a custom flag, and track its state manually:

let isGrouped = false;

function toggleGroup() {
    const button = document.querySelector('.group-toggle');

    if (isGrouped) {
        gantt.groupBy(false);
        button.value = 'Group by priority';
        gantt.message('Tasks are ungrouped.');
    } else {
        gantt.groupBy({
            groups: gantt.serverList('priority'),
            relation_property: 'priority',
            group_id: 'key',
            group_text: 'label'
        });
        
        button.value = 'Ungroup';
        gantt.message('Tasks are grouped.');
    }

    isGrouped = !isGrouped;
}

Alternatively, you can check if there are tasks with the $virtual property in the task datastore, as virtual tasks are created when the Gantt is grouped:

function isGanttGrouped() {
    const tasksStore = gantt.getDatastore('task');
    const isGrouped = Object.values(tasksStore.pull).some(task => task.$virtual);
    gantt.message(isGrouped ? 'Tasks are grouped.' : 'Tasks are not grouped.');
}

Here’s an example: DHTMLX Snippet Tool