Skip to content

Commit eaf335d

Browse files
authored
Update index.html
1 parent 97ab3d9 commit eaf335d

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

index.html

+41-6
Original file line numberDiff line numberDiff line change
@@ -1325,13 +1325,48 @@ <h3 id="spotweb-indexers">Spotweb Indexers</h3>
13251325

13261326
<a href="#top">Back to top</a>
13271327

1328-
<script>
1329-
document.addEventListener('DOMContentLoaded', () => {
1330-
new Tablesort(document.getElementById('table-1'));
1331-
new Tablesort(document.getElementById('table-2'));
1332-
new Tablesort(document.getElementById('table-3'));
1328+
<script src="https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.2.1/tablesort.min.js"></script>
1329+
<script>
1330+
document.addEventListener('DOMContentLoaded', () => {
1331+
// Initialize Tablesort for each table
1332+
new Tablesort(document.getElementById('table-1'));
1333+
new Tablesort(document.getElementById('table-2'));
1334+
new Tablesort(document.getElementById('table-3'));
1335+
});
1336+
1337+
// Extend Tablesort to support custom sorting
1338+
Tablesort.extend('data-group', function(item) {
1339+
return item.getAttribute('data-group') || item.innerText;
1340+
});
1341+
1342+
// Custom function to sort table and keep groups together
1343+
function sortTable(tableId, columnIndex) {
1344+
const table = document.getElementById(tableId);
1345+
const tbody = table.querySelector('tbody');
1346+
const rows = Array.from(tbody.querySelectorAll('tr'));
1347+
1348+
// Create a map of group to rows
1349+
const groups = rows.reduce((acc, row) => {
1350+
const group = row.getAttribute('data-group') || row.rowIndex;
1351+
if (!acc[group]) acc[group] = [];
1352+
acc[group].push(row);
1353+
return acc;
1354+
}, {});
1355+
1356+
// Get groups in sorted order based on the first row of each group
1357+
const sortedGroups = Object.keys(groups).sort((a, b) => {
1358+
const cellA = groups[a][0].cells[columnIndex].innerText.toLowerCase();
1359+
const cellB = groups[b][0].cells[columnIndex].innerText.toLowerCase();
1360+
return cellA.localeCompare(cellB);
1361+
});
1362+
1363+
// Append rows to tbody in sorted order
1364+
tbody.innerHTML = '';
1365+
sortedGroups.forEach(group => {
1366+
groups[group].forEach(row => tbody.appendChild(row));
13331367
});
1334-
</script>
1368+
}
1369+
</script>
13351370

13361371

13371372
</body>

0 commit comments

Comments
 (0)