Skip to content

Commit d456250

Browse files
committed
table
1 parent 062bb22 commit d456250

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

content/learningmodule/table.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,4 @@ function myFunction() {
2323
tr[i].style.display = "none";
2424
}
2525
}
26-
}
27-
const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
28-
29-
const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
30-
v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2)
31-
)(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));
32-
33-
// do the work...
34-
document.querySelectorAll('th').forEach(th => th.addEventListener('click', (() => {
35-
const table = th.closest('table');
36-
Array.from(table.querySelectorAll('tr:nth-child(n+2)'))
37-
.sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc))
38-
.forEach(tr => table.appendChild(tr) );
39-
})));
26+
}

0 commit comments

Comments
 (0)