|
@@ -35,19 +35,18 @@ app.clearFilter = function() {
|
|
|
app.filterTable("");
|
|
|
};
|
|
|
|
|
|
-app.sortTable = function() {
|
|
|
- // borrowed from https://stackoverflow.com/a/49041392/7342859
|
|
|
- const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
|
|
|
+app.getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
|
|
|
|
|
|
- const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
|
|
|
+app.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));
|
|
|
+ )(app.getCellValue(asc ? a : b, idx), app.getCellValue(asc ? b : a, idx));
|
|
|
|
|
|
- // do the work...
|
|
|
+app.sortTable = function() {
|
|
|
+ // borrowed from https://stackoverflow.com/a/49041392/7342859
|
|
|
document.querySelectorAll('th').forEach(th => th.addEventListener('click', (() => {
|
|
|
const table = document.getElementById("dataRows");
|
|
|
Array.from(table.querySelectorAll('tr:nth-child(n+2)'))
|
|
|
- .sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc))
|
|
|
+ .sort(app.comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc))
|
|
|
.forEach(tr => table.appendChild(tr) );
|
|
|
|
|
|
const sorted = " (sorted)";
|