diff --git a/summary/99_footer.html b/summary/99_footer.html index 1c4c9f4..1ab7f60 100644 --- a/summary/99_footer.html +++ b/summary/99_footer.html @@ -1,5 +1,6 @@ - +*/ + + // Permet de sélectionner une ligne en cliquant dessus + document.addEventListener('DOMContentLoaded', () => { + const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent; + + const comparer = (idx, asc) => (a, b) => { + const v1 = getCellValue(asc ? a : b, idx); + const v2 = getCellValue(asc ? b : a, idx); + return !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.localeCompare(v2); + }; + + // permet de trier le tableau + document.querySelectorAll('table th').forEach(th => { + th.addEventListener('click', () => { + const table = th.closest('table'); + const tbody = table.querySelector('tbody') || table; + const rows = Array.from(tbody.querySelectorAll('tr:nth-child(n+2)')); // ignore header + const index = Array.from(th.parentNode.children).indexOf(th); + const asc = !th.classList.contains('asc'); + table.querySelectorAll('th').forEach(th => th.classList.remove('asc', 'desc')); + th.classList.toggle('asc', asc); + th.classList.toggle('desc', !asc); + rows.sort(comparer(index, asc)).forEach(row => tbody.appendChild(row)); + }); + }); + }); + + \ No newline at end of file