Event handler for header clicks in DHTMLX Scheduler

人盡茶涼 提交于 2019-12-11 11:33:55

问题


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 listener with date for which click was performed.

How can we do this with DHTMLX Scheduler?


回答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 : new Date(dateValue);
            var unitId = target.getAttribute("data-scale-unitId") ? target.getAttribute("data-scale-unitId") : {{your unit id in unit view}};
            // ...
        }

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



回答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



来源:https://stackoverflow.com/questions/33632200/event-handler-for-header-clicks-in-dhtmlx-scheduler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!