search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to scroll to "currenttime" cell on start

Asked by Andrea
1 month ago.

Hi,
I use a calendar that is about twice as long as the screen, how can I position (scroll) the view on the cell that represents the "current time" at startup?

Comment posted by Dan Letecky [DayPilot]
1 month ago.

You can use the scrollTo() method:

ngAfterViewInit(): void {
  this.scheduler.control.scrollTo(DayPilot.Date.today());
}

See also:
https://api.daypilot.org/daypilot-scheduler-scrollto/

Just note that it needs to be used in ngAfterViewInit or later. The Scheduler component is not ready yet in ngOnInit.

Comment posted by Anonymous
1 month ago.

Hi, thanks for the answer, but the problem for me is that I use a "calendar", not a "schedule": is there a scrollTo function in this case?

Answer posted by Dan Letecky [DayPilot]
1 month ago.

The Calendar should scroll to the first business hour (businessBeginsHour) by default.

If you want to scroll to a different hour, you can use scrollToHour() method:
https://api.daypilot.org/daypilot-calendar-scrolltohour/

Comment posted by Anonymous
1 month ago.

I've a DayPilotCalendarComponent in my angular component, but I didn't find the scrollToHour() method; is it available in Angular version too?

Comment posted by Dan Letecky [DayPilot]
1 month ago.

It looks like it was missing in the TypeScript definitions. It's now available in the latest sandbox build (2021.4.5133):

https://release.daypilot.org/changes/js/

In previous releases, you can cast the DayPilot.Calendar object to any to access the method:

const cal = this.calendar.control as any;
cal.scrollToHour(10);
Comment posted by Anonymous
1 month ago.

Right, thks!

New Reply
This reply is
Your name (optional):