If you use dhtmlxScheduler 6.0 or earlier, see details here.
To display tooltips for events, you should activate the Tooltip extension once on the page.
scheduler.plugins({
tooltip: true
});
After that tooltips will be displayed with the default settings.
Once the extension is activated, tooltips will be automatically displayed with the default settings.
By default, tooltips display 3 properties of an event:
To set a custom text for tooltips, use the tooltip_text template:
scheduler.templates.tooltip_text = function(start,end,event) {
return "<b>Event:</b> "+event.text+"<br/><b>Start date:</b> "+
scheduler.templates.tooltip_date_format(start)+"<br/>"+
"<b>End date:</b> "+scheduler.templates.tooltip_date_format(end);
};
You can access the object of tooltip as scheduler.ext.tooltips.tooltip. This object allows manipulating the position, content and visibility of tooltip via a set of methods:
There are several methods that allow controlling behavior of the tooltip while hovering over DOM elements.
adds a tooltip with an extended configuration. The method takes an object with the tooltip settings as a parameter. The settings that can be adjusted via the method are the following:
adds a tooltip for the specified Scheduler element. It is a more simplified version of the attach() method. The method takes as a parameter an object with the tooltip details. This object has the following properties:
removes a tooltip. As a parameter the method takes:
By default, tooltips are added just to the Scheduler events, but you can also set tooltips for any other Scheduler element.
There are two corresponding methods in the tooltip API for this purpose:
Note, the scheduler.ext.tooltips.tooltipFor() method must be called after the Scheduler initialization is complete. For instance, you can specify the method inside the onSchedulerReady event handler like this:
scheduler.attachEvent("onSchedulerReady", function(){
scheduler.ext.tooltips.tooltipFor({
selector: ".dhx_matrix_scell",
html: function (event, node) {
const sectionId = scheduler.getActionData(event).section;
const timeline = scheduler.getView("timeline");
var section = timeline.y_unit[timeline.order[sectionId]];
return `Tooltip for <b>${section.label}</b>`;
}
});
});
Or you can use the following way:
scheduler.init("scheduler_here");
scheduler.ext.tooltips.tooltipFor({
selector: ".dhx_matrix_scell",
html: function (event, node) {
const sectionId = scheduler.getActionData(event).section;
const timeline = scheduler.getView("timeline");
var section = timeline.y_unit[timeline.order[sectionId]];
return `Tooltip for <b>${section.label}</b>`;
}
});
A tooltip added in this way will follow the mouse pointer and use the tooltip_offset_x, tooltip_offset_y, tooltip_timeout, and tooltip_hide_timeout settings.
This method allows adding a tooltip with an extended configuration to adjust the tooltip behavior to the movement of the mouse pointer.
There is a possibility to modify the default behavior of the tooltip. It can be achieved by removing the default tooltip handler and adding a custom one. Follow the steps below:
// remove the built-in tooltip handler from tasks
scheduler.ext.tooltips.detach(`[${scheduler.config.event_attribute}]`);
scheduler.ext.tooltips.tooltipFor({
selector: `[${scheduler.config.event_attribute}]`,
html: (event: MouseEvent) => {
if (scheduler.config.touch && !scheduler.config.touch_tooltip) {
return;
}
const evNode = event.target.closest(`[${scheduler.config.event_attribute}]`);
const evId = evNode.getAttribute(scheduler.config.event_attribute);
if(scheduler.getEvent(evId)){
const ev = scheduler.getEvent(evId);
return scheduler.templates.tooltip_text(ev.start_date, ev.end_date, ev);
}
return null;
},
global: false
});
You can configure the time of tooltips showing and hiding via the related settings.
To specify the time period (in milliseconds) before a tooltip for a task will appear, use the tooltip_timeout property:
scheduler.config.tooltip_timeout = 50;
scheduler.init("scheduler_here");
To define how long (in milliseconds) a tooltip will be shown after the user moves the cursor to another position, use the tooltip_hide_timeout property:
scheduler.config.tooltip_hide_timeout = 5000;
scheduler.init("scheduler_here");
The position of a tooltip can be configured by changing the offsets of its default position via the two configuration properties:
scheduler.config.tooltip_offset_x = 30;
scheduler.config.tooltip_offset_y = 40;
scheduler.init("scheduler_here");
By default tooltips are attached to document.body. If necessary, you can limit showing of tooltips to the container before initialization of Scheduler by using the code below:
scheduler.attachEvent("onSchedulerReady", function(){
var tooltips = scheduler.ext.tooltips;
tooltips.tooltip.setViewport(container);
});
scheduler.init("scheduler_here");
Back to top