Timeline view y-units

Hello, I can not find nor figure out how to limit my y-unit to what is returned in the events data.

Meaning I have an instructor(can be multiple instructors) field for my event, I use a server list to populate my y-units. The server list pulls all instructors from the instructor table and displays them all. I just want the instructors that are tied to an event to be displayed. Is this possible?

Any help would be greatly appreciated! Thanks in advance.

Hello @RonM ,

Just to clarify, you want to display only sections(instructors), that have events, on them, am I right?

There is no built-in config for that, but you can implement it with the selectEvents method:
https://docs.dhtmlx.com/scheduler/timeline_view.html#timelineobjectapi
which allows you to get events assigned for some section, and the updateCollection method, which allows you to dynamically update elements of the Y-axis.

The logic of the solution could be to loop through all sections, with the selectEvents => remove all empty sections from the array, that you will use as the y_unit property => call the udpateCollection method with the new array:

var sections = scheduler.serverList("sections", [
  {key:1, label:"Apartment 1"},
  {key:2, label:"Apartment 2"},
  {key:3, label:"Apartment 3"},
  {key:4, label:"Apartment 4"}
]);

function getClear(arr){
  var clearedSections = [];
  var timeline = scheduler.getView();
  arr.forEach(el => {
    var evs = timeline.selectEvents({
      section: el.key,
    }).length
    if(evs) clearedSections.push(el)
      })
  return clearedSections;
}
...

function filterEmptySections(){
  scheduler.updateCollection("sections", getClear(sections));
}

Here is a demo:
https://snippet.dhtmlx.com/5/e2111ef27

Or you can provide some server-side filtering, and return only required sections from the backend.

If you need something different, could you please clarify the requirement?

1 Like

Hi Siarhei,

Thank you for answering my question!

That is exactly what I am looking for, I will check out your suggestion and reply with how I made out.