Adds sortTable function

This commit is contained in:
Michael Beck
2025-02-06 19:39:22 +01:00
parent 6d391eb6eb
commit 417a47d6a7

View File

@@ -65,6 +65,32 @@ function downloadSelectedFiles() {
} }
} }
function sortTable(columnIndex, tableId) {
const table = document.getElementById(tableId);
const tbody = table.querySelector('tbody');
const rows = Array.from(tbody.rows);
const isAscending = table.getAttribute('data-sort-asc') === 'true';
rows.sort((rowA, rowB) => {
const cellA = rowA.cells[columnIndex].innerText.toLowerCase();
const cellB = rowB.cells[columnIndex].innerText.toLowerCase();
if (cellA < cellB) {
return isAscending ? -1 : 1;
}
if (cellA > cellB) {
return isAscending ? 1 : -1;
}
return 0;
});
// Toggle the sorting order for the next click
table.setAttribute('data-sort-asc', !isAscending);
// Append sorted rows back to the tbody
rows.forEach(row => tbody.appendChild(row));
}
// Function to check or uncheck all checkboxes in a table by checking or unchecking the "CheckAll" checkbox // Function to check or uncheck all checkboxes in a table by checking or unchecking the "CheckAll" checkbox
function checkAllCheckboxes(tableId, checkAllCheckboxId) { function checkAllCheckboxes(tableId, checkAllCheckboxId) {
const table = document.getElementById(tableId); const table = document.getElementById(tableId);