Don't rescroll to the top when updating functionality
This commit is contained in:
parent
deedc2fad3
commit
aff2c1d862
@ -19,8 +19,11 @@ function saveData() {
|
|||||||
|
|
||||||
let showAllMatches = false; // false = future matches only; true = all matches
|
let showAllMatches = false; // false = future matches only; true = all matches
|
||||||
|
|
||||||
|
let initialLoad = true;
|
||||||
function renderTable() {
|
function renderTable() {
|
||||||
const container = document.getElementById('attendance-table');
|
const container = document.getElementById('attendance-table');
|
||||||
|
// Save scroll position of the container
|
||||||
|
const scrollTop = window.scrollY;
|
||||||
container.innerHTML = '';
|
container.innerHTML = '';
|
||||||
const table = document.createElement('table');
|
const table = document.createElement('table');
|
||||||
// Header row
|
// Header row
|
||||||
@ -161,8 +164,14 @@ function renderTable() {
|
|||||||
container.appendChild(table);
|
container.appendChild(table);
|
||||||
// Scroll to the most current match row after rendering
|
// Scroll to the most current match row after rendering
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
if (initialLoad) {
|
||||||
const row = document.getElementById('current-match-row');
|
const row = document.getElementById('current-match-row');
|
||||||
if (row) row.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
if (row) row.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||||
|
initialLoad = false;
|
||||||
|
} else {
|
||||||
|
// Restore previous scroll position
|
||||||
|
window.scrollTo({ top: scrollTop });
|
||||||
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user