Browse Source

Smaller is better

Piotr Czajkowski 4 years ago
parent
commit
066700c3ab
1 changed files with 6 additions and 7 deletions
  1. 6 7
      static/processResults.js

+ 6 - 7
static/processResults.js

@@ -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)";