Skip to content Skip to sidebar Skip to footer

Event Handler For Header Clicks In Dhtmlx Scheduler

We use DHTMLX Scheduler and we would like to attach a listener for clicks on header in week view, unit view, etc. We didn't find a way to do this. We also need date in our listene

Solution 1:

DHTMLX Scheduler does not provide an event for clicks on header, so in order to do this, you need to change templates for your views first:

var toStr = scheduler.date.date_to_str(scheduler.config.day_date);
scheduler.templates.week_scale_date = (dt) =>"<span data-scale-date='" + dt.valueOf() + "'>" + toStr(dt) + "</span>";
scheduler.templates.unit_scale_text = (key, label) =>"<span data-scale-date='0' data-scale-unitId='" + key + "'>" + label + "</span>";
// ...

After templates are changed, you can attach an event listener to #scheduler_here and filter for clicks on header:

document.getElementById("scheduler_here").addEventListener("click", (evt) => {
    var event = evt || window.event;
    var target = event.target || event.srcElement;

    if (target && target.nodeName === "SPAN" && target.parentElement && target.parentElement.classList && target.parentElement.classList.contains("dhx_scale_bar")) {
        var dateStr = target.getAttribute("data-scale-date");
        if (dateStr) {
            var dateValue = parseInt(dateStr, 10);
            var date = dateValue === 0 ? scheduler.getState().date : newDate(dateValue);
            var unitId = target.getAttribute("data-scale-unitId") ? target.getAttribute("data-scale-unitId") : {{your unit id in unit view}};
            // ...
        }

        evt.stopPropagation();
        evt.preventDefault();
    }
}, false);

Solution 2:

DHTMLX Scheduler provides events which fire when the user makes a single or double click on a cell on the x-axis (the Timeline view only):

onXScaleClick

onXScaleDblClick

Post a Comment for "Event Handler For Header Clicks In Dhtmlx Scheduler"