Don't reset scroll on timeline view when changing the view

Hello, I want to maintain the date scrolled when changing views when the scrollable option is set to true. There is a way to avoid scroll or get the date of the view content in the scroll?

Thanks

Hello @Cesar_Smerling ,

, I want to maintain the date scrolled when changing views when the scrollable option is set to true.

You can do it by saving the old date before changing the view onBeforeViewChange with the dateFromPos method, and use it in the scrollTo method, from the onViewChange event(inside small timeout, due to the rendering specific).

The code may look like follows:

var scrollState;
scheduler.attachEvent("onViewChange", function (new_mode , new_date){
  var timeline = scheduler.getView();
  setTimeout(() => {
    timeline.scrollTo(new Date(scrollState));
  },1)
});
scheduler.attachEvent("onBeforeViewChange", function(old_mode,old_date,mode,date){
  var timeline = scheduler.getView(); 
  scrollState = timeline.dateFromPos(timeline.getScrollPosition().left)
  return true;
});

Here is a demo when you can test it:
http://snippet.dhtmlx.com/5/0c19c640a

Kind regards,

1 Like

Thanks, this works fine for our purpose.