This commit is contained in:
Aevann1 2022-03-06 05:54:30 +02:00
parent 51ba200c7b
commit 512f3c8907
3 changed files with 14 additions and 19 deletions

View file

@ -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;
}
}
}
}

View file

@ -4,7 +4,7 @@
{% block content %}
<script src="/static/assets/js/sort_table.js?v=240"></script>
<script src="/static/assets/js/sort_table.js?v=241"></script>
<pre class="d-none d-md-inline-block"></pre>
<h5 style="font-weight:bold;">Admins</h5>

View file

@ -1,6 +1,6 @@
{% extends "default.html" %}
{% block content %}
<script src="/static/assets/js/sort_table.js?v=240"></script>
<script src="/static/assets/js/sort_table.js?v=241"></script>
<pre>