diff --git a/static/download_results.js b/static/download_results.js index 0a98b25..691df21 100644 --- a/static/download_results.js +++ b/static/download_results.js @@ -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 checkAllCheckboxes(tableId, checkAllCheckboxId) { const table = document.getElementById(tableId);