Auto scroll fullcalendar V5( resourceTimelineWeek View) to current date and time

1.5k Views Asked by At

I am using Fullcalendar V5. While trying to set the scrollTime to the current date and time in the resourceTimelineWeek view, time only is working fine, but how shall I set the date scrolling.

var scrollTime = moment().format("HH") + ":00:00"; 
    
 document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar');
    var calendar = new FullCalendar.Calendar(calendarEl, {
now: new Date(),
scrollTime: scrollTime
}
)};

Now, it is 09:30 and the time is showing correctly. But the date is Oct 01, which is still Sep 27 on the calendar scroll view. Time only working

1

There are 1 best solutions below

1
On

Tested on FullCalendar 5.8.0 (using jQuery and moment.js)

options = {
    datesSet: ({ view }) => {
        if (view.type === 'resourceTimelineWeek') {
            const scroller = $('.fc-scrollgrid-section-body .fc-scroller').last();
            const [date] = moment().toISOString().split(':');
            const position = $(`.fc-timeline-slot[data-date^="${date}"]`).last().position();
            if (position) {
                scroller.scrollLeft(position.left);
            }
        }
    }
}