Added sorting to Hold Lot table.
This commit is contained in:
@ -157,4 +157,68 @@ function toggleWeek() {
|
||||
for (let i = 0; i < rptTableDiv.length; i++) {
|
||||
rptTableDiv[i].classList.toggle("hidden");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sortTable(n) {
|
||||
var table, rows, switching, i, x, y, shouldSwitch, dir, switchCount = 0;
|
||||
table = document.getElementById("sortTable");
|
||||
switching = true;
|
||||
dir = "asc";
|
||||
|
||||
while (switching) {
|
||||
switching = false;
|
||||
rows = table.rows;
|
||||
|
||||
for (i = 1; i < rows.length - 1; i++) {
|
||||
shouldSwitch = false;
|
||||
x = rows[i].getElementsByTagName("td")[n];
|
||||
y = rows[i + 1].getElementsByTagName("td")[n];
|
||||
|
||||
if (compareStrings(n == 3, dir, x.innerHTML.toLowerCase(), y.innerHTML.toLowerCase())) {
|
||||
shouldSwitch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldSwitch) {
|
||||
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
|
||||
switching = true;
|
||||
switchCount++;
|
||||
} else {
|
||||
if (switchCount == 0 && dir == "asc") {
|
||||
dir = "desc";
|
||||
switching = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
icon = document.getElementById("i-" + n);
|
||||
|
||||
icon.classList.toggle("fa-arrow-down")
|
||||
icon.classList.toggle("fa-arrow-up")
|
||||
}
|
||||
|
||||
function compareStrings(isDate, dir, string1, string2) {
|
||||
if (isDate) {
|
||||
var date1 = new Date(string1);
|
||||
var date2 = new Date(string2);
|
||||
|
||||
console.log(date1);
|
||||
console.log(date2);
|
||||
|
||||
if (dir == "asc" && date1 > date2)
|
||||
return true;
|
||||
|
||||
if (dir == "desc" && date1 < date2)
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (dir == "asc" && string1 > string2)
|
||||
return true;
|
||||
|
||||
if (dir == "desc" && string1 < string2)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user