visjs / vis-timeline

📅 Create a fully customizable, interactive timelines and 2d-graphs with items and ranges.
https://visjs.github.io/vis-timeline/
Other
1.74k stars 302 forks source link

Changing/toggling classes in timeline items #1790

Open erevodifosin opened 2 months ago

erevodifosin commented 2 months ago

Hello,

I was trying to change/toggle some classes on the timeline items in the runtime in order to upgrade the UX but it is a bit weird the way I managed to achieve it. First of all in some items I use "className": "cancelled" which adds the corresponding class in the element. The task is to toggle the specific class in the selected item. I was not able to find something related in the documentation.

I tried the below with a bit of success but then when I click somewhere else the toggle is reverted.

temp = document.getElementsByClass("vis-selected")
temp[0].classList.toggle("cancelled");

The workaround I managed to figure out was to remove the class name in my db and then reload the items of the timeline. Am I missing something here or my workaround is the only solution for the moment? It would be nice to have a method to toggle a class in the items in runtime.