angular-calendar icon indicating copy to clipboard operation
angular-calendar copied to clipboard

Scroll to current time automatically

Open monalipatwa opened this issue 8 years ago • 7 comments

Can day view calendar scroll to current time automatically when the calendar loads first time?

monalipatwa avatar Apr 11 '18 09:04 monalipatwa

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.

etwillbefine avatar Apr 13 '18 15:04 etwillbefine

Oups sorry the first point was more related to the week view rather than the day view which always shows 24h

etwillbefine avatar Apr 13 '18 15:04 etwillbefine

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 avatar Apr 17 '18 10:04 mattlewis92

@mattlewis92 Can you please provide example for that?

Virendra8Satva avatar May 29 '20 09:05 Virendra8Satva

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
  }

stefanzugal avatar Mar 23 '21 08:03 stefanzugal

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);
    }

LePtitJoNadeau avatar Jun 15 '22 15:06 LePtitJoNadeau

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());
    }

LePtitJoNadeau avatar Jun 15 '22 16:06 LePtitJoNadeau