Scroll to current time automatically
Can day view calendar scroll to current time automatically when the calendar loads first time?
Just out of curiosity: Scrolling either hides the header or some events and you might not know which day is shown. Wouldn't it be better to only show a few limited events with the option to show more or expand them all?
Anyway I'm not sure if this is something that will be implemented in this library. You should be able to add the desired behaviour by using the scrollHeight of your page/parent component.
Oups sorry the first point was more related to the week view rather than the day view which always shows 24h
There isn't actually any scrolling baked into the day view, but you can implement this yourself, the pseudocode would be dayViewComponentElement.top + (hourToScrollTo * 60). Hope that helps! 😄
@mattlewis92 Can you please provide example for that?
We are using it for the week-based view - I would assume that it should work for the day-based view in a similar manner (you might need to adapt the way how the dom element is selected, though):
@ViewChild('calendar', {static: false, read: ElementRef}) set calendarNativeElement(element: ElementRef) {
const eventsContainer = element.nativeElement.getElementsByClassName('cal-time-events')[0];
eventsContainer.scrollTop = 44 * this.calendarDayStart; // 44 is the height for weeks, I guess 60 for days
}
I did this to scroll view to current time
public ngOnInit(): void {
setTimeout(() => {
const elements = document.getElementsByClassName("cal-current-time-marker");
for (let i = 0; i < elements.length; i++) {
elements[i].scrollIntoView({block: 'center'});
}
}, 0);
}
Or you can do that
constructor(private _elementRef: ElementRef ) { }
public ngOnInit(): void {
const selector = '.cal-current-time-marker';
setTimeout(() => this._elementRef.nativeElement.querySelector(selector)?.scrollIntoView());
}