calendar icon indicating copy to clipboard operation
calendar copied to clipboard

How to scroll today when "today" button is clickedn in resourceTimelineWeek view

Open derkan opened this issue 1 year ago • 3 comments

Hi,

While at resourceTimelineWeek view, if user clicks today button, view is scrolled to start of current week. How can I make it to scroll to current day in the week?

Regards

derkan avatar Aug 28 '24 10:08 derkan

Good question. There is currently no method for such scrolling. I will try to come up with something in future versions.

vkurko avatar Aug 29 '24 06:08 vkurko

Maybe it helps somehow: This is what I use as a workaround at the moment for scolling to the current day in Timeline Month for example:

function scrollToDay(containerSelector, todaySelector) { const scrollContainer = document.querySelector(containerSelector); const todayElement = document.querySelector(todaySelector);

if (scrollContainer && todayElement) {
    const todayPosition = todayElement.offsetLeft;

    scrollContainer.scrollTo({
        left: todayPosition,
        behavior: 'smooth', 
    });
} else {
    console.error('Scroll container or day element not found.');
}

}

Usage: scrollToToday('.ec-body', '.ec-day.ec-today');

inu-web avatar Dec 16 '24 15:12 inu-web

Hi, Personally, I use this function to scroll to the desired date in the resourceTimelineWeek.

scrollTo(date, behavior = 'smooth') {

	if (!date) {
		return;
	}

	console.log('Scroll to date:', date);

	const intervalId = setInterval(() => {
		const targetDateHeaderElement = this.element.querySelector(`.ec-header [datetime="${date}"]`);
		if (targetDateHeaderElement) {
			const bodyElement = this.element.querySelector('.ec-body');
			if (bodyElement) {
				const headerRect = targetDateHeaderElement.getBoundingClientRect();
				const bodyRect = bodyElement.getBoundingClientRect();
				const scrollLeft = headerRect.left - bodyRect.left + bodyElement.scrollLeft;
				bodyElement.scrollTo({left: scrollLeft, behavior: behavior});
			}
			clearInterval(intervalId);
		}
	}, 100);
}

rrrb11 avatar Feb 05 '25 08:02 rrrb11