I just found this tutorial : https://www.geeksforgeeks.org/how-to-create-a-table-with-fixed-header-and-scrollable-body/ It works perfectly for me but I need to refresh the web page and be in the same row as before in the table (for example a table with 10 000 rows, i need to stay at the 600th row after resfreshing the web page). I just add :
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var scrollpos = localStorage.getItem('scrollpos');
if (scrollpos) window.scrollTo(0, scrollpos);
});
window.onbeforeunload = function(e) {
localStorage.setItem('scrollpos', window.scrollY);
};
</script>
But it doesn't work because I stay on a web page fixed and i'm scrolling inside it. it's because my scrolling vertical bar is contained in the table and not in the web page.
How can I reload ly web page keeping the position of my vertical scroll bar ?
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<!---Without refresh Dispositif-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var scrollpos = localStorage.getItem('scrollpos');
if (scrollpos) window.scrollTo(0, scrollpos);
});
window.onbeforeunload = function(e) {
localStorage.setItem('scrollpos', window.scrollY);
};
</script>
<style>
.fixTableHead {
overflow-y: auto;
height: 600px;
}
.fixTableHead thead th {
position: sticky;
top: 0;
}
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
padding: 8px 15px;
border: 2px solid #529432;
}
th {
background: #ABDD93;
}
</style>
<div class="fixTableHead">
<table class="table table-striped header-fixed" id="tableau">
<thead>
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
<tr>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
<tr>
<td>13</td>
<td>14</td>
<td>15</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Thank you