From aff2c1d8621ff1bad31fa135527d49aa0405dd6e Mon Sep 17 00:00:00 2001 From: Greg Date: Sat, 10 May 2025 23:04:08 +0200 Subject: [PATCH] Don't rescroll to the top when updating functionality --- static/app.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/static/app.js b/static/app.js index b49b1ad..21cd6f9 100644 --- a/static/app.js +++ b/static/app.js @@ -19,8 +19,11 @@ function saveData() { let showAllMatches = false; // false = future matches only; true = all matches +let initialLoad = true; function renderTable() { const container = document.getElementById('attendance-table'); + // Save scroll position of the container + const scrollTop = window.scrollY; container.innerHTML = ''; const table = document.createElement('table'); // Header row @@ -161,8 +164,14 @@ function renderTable() { container.appendChild(table); // Scroll to the most current match row after rendering setTimeout(() => { - const row = document.getElementById('current-match-row'); - if (row) row.scrollIntoView({ behavior: 'smooth', block: 'center' }); + if (initialLoad) { + const row = document.getElementById('current-match-row'); + if (row) row.scrollIntoView({ behavior: 'smooth', block: 'center' }); + initialLoad = false; + } else { + // Restore previous scroll position + window.scrollTo({ top: scrollTop }); + } }, 0); }