Click event on groups vis.js timeline

543 Views Asked by At

I need to add an event (click) on groups, each time i click on a group, it should open a new page, i read through the vis.js timeline documentation and i dont see any event handling on groups, there is only an event click on items but not on groups. The click event on items :

 timeline.on("click", function (properties) {  
        // Check if an item was clicked on
        if (properties.item){
          // An item was clicked, get the item from dataset
          const item = items.get(properties.item);
          console.log('click event - title:', item.title); 
        }
    });

is there a visjs method i dont know about ? or is there any way to add an event listener on the groups ? ps : i dont have nested groups.

1

There are 1 best solutions below

0
Di_ On

For anyone wondering about the solution for this problem, this could be done using the timeline options groupTemplate and groupEditable :

var options = {
        groupTemplate: function(group) {
            var container = document.createElement('div');
            var label = document.createElement('span');
            label.innerHTML = group.content;
            container.insertAdjacentElement('afterBegin',label);
            label.addEventListener('click',function() {
                // add instructions here
            });
            return container;
          },
          groupEditable: true
    };