Context menu in chart area


Hi support,
I want two different context menu in tree area and chart area. can you pls share code snippet for this



There is no built-in context menu in the Gantt, but there is onContextMenu event which fires on the right click and which you can use to show a menu: ;
To create a context menu in different parts of the Gantt, you can track your clicks to the grid and chart areas with the help of gantt.utils module: ;
It can help you to get the grid and chart areas provided by the CSS classes, for example:

let domHelpers = gantt.utils.dom;
    if (domHelpers.closest(, `.gantt_grid_data`)) {
        //your code

You can create your custom context menu or use third-party libraries. For example, a simple context menu with some buttons can be created with this html code:

let custom_menu_2 = `
           style="top: ${e.clientY}px; left: ${e.clientX}px;" 
      <input type=button value="Open Lightbox" onclick="gantt.showLightbox(${task_id})">
      <input type=button value="Delete Task" onclick="gantt.deleteTask(${task_id})">
      <input type=button value="Show progress" onclick="gantt.message(${gantt.getTask(task_id).progress * 100}+'%')">
let el = document.createElement("div");
el.innerHTML = custom_menu_2;

At the end, you need to close the context menu. One of the options is creating a function to remove menu:

function remove_context_menu() {
    let el = document.querySelector('.custom_menu');
    if (el) {
        el.innerHTML = null;

Another option of creating a context menu is to use the context menu from the dhtmlxSuite library. The dhtmlXMenu component is initialized using the constructor new dhtmlXMenuObject() and can be called when the onContextMenu event fires. You can create the required functionality with addNewChild method and attaching onClick event to your menu object: ; ;
Please check the snippet with two different context menus (one from dhtmlxSuite library and another is a custom solution):