booba
This commit is contained in:
parent
51ba200c7b
commit
512f3c8907
3 changed files with 14 additions and 19 deletions
|
@ -1,8 +1,7 @@
|
|||
function sort_table(n) {
|
||||
var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
|
||||
var table, rows, switching, i, x, y, shouldSwitch, switchcount = 0;
|
||||
table = document.getElementById("sortable_table");
|
||||
switching = true;
|
||||
dir = "desc";
|
||||
while (switching) {
|
||||
switching = false;
|
||||
rows = table.rows;
|
||||
|
@ -10,27 +9,23 @@ function sort_table(n) {
|
|||
shouldSwitch = false;
|
||||
x = rows[i].getElementsByTagName("TD")[n];
|
||||
y = rows[i + 1].getElementsByTagName("TD")[n];
|
||||
if (dir == "asc") {
|
||||
if (parseInt(x.innerHTML) > parseInt(y.innerHTML)) {
|
||||
shouldSwitch = true;
|
||||
break;
|
||||
}
|
||||
} else if (dir == "desc") {
|
||||
if (parseInt(x.innerHTML) < parseInt(y.innerHTML)) {
|
||||
shouldSwitch = true;
|
||||
break;
|
||||
}
|
||||
const x_child = x.getElementsByTagName('a')
|
||||
if (x_child) {
|
||||
x = x_child[0]
|
||||
}
|
||||
const y_child = y.getElementsByTagName('a')
|
||||
if (y_child) {
|
||||
y = y_child[0]
|
||||
}
|
||||
if (parseInt(x.innerHTML) < parseInt(y.innerHTML)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue