diff options
Diffstat (limited to 'parts/end.html')
| -rwxr-xr-x | parts/end.html | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/parts/end.html b/parts/end.html deleted file mode 100755 index cc51027..0000000 --- a/parts/end.html +++ /dev/null @@ -1,46 +0,0 @@ - </tbody>
- </table>
- </div>
-</body>
-
-<script type="text/javascript">
- const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
- prevColumnSorted = document.getElementsByClassName("current-sort")[0];
-
- const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
- v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2)
- )(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));
-
- function doSort(th) {
- console.log("Doing sort to: ", th.textContent, th);
-
- const table = th.closest('table');
- const tbody = table.querySelector('tbody');
- const columnIndex = Array.from(th.parentNode.children).indexOf(th);
-
- // Toggle sort direction
- if (prevColumnSorted == th) {
- this.asc = !this.asc;
- } else {
- this.asc = true;
- }
-
- // Get all rows, sort them, then reappend to tbody
- const rows = Array.from(tbody.querySelectorAll('tr'));
- const sortedRows = rows.sort(comparer(columnIndex, this.asc));
-
- sortedRows.forEach(row => tbody.appendChild(row));
- prevColumnSorted = th;
- }
-
- // Event listeners and initial sort
- document.querySelectorAll('th').forEach(th => th.addEventListener('click', () => {
- document.getElementsByClassName("current-sort")[0].classList.remove("current-sort");
- th.classList.add("current-sort");
- doSort(th);
- }));
-
- doSort(document.getElementsByClassName("current-sort")[0]);
-</script>
-
-</html>
|