commit: b11b1cabc425ade2480ac99e52aa298ad273086c
parent b74ef944c3cce5610479e589ca16383b1f2ed0db
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 9 Mar 2023 05:50:15 +0100
javascript/sorttable.js: Don't let [].sort() cast to string
Diffstat:
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/javascript/sorttable.js b/javascript/sorttable.js
@@ -60,6 +60,13 @@ sorttable.makeSortable = function(table) {
}
};
+sorttable.compareFn = function(a, b) {
+ // Note: Returns are reversed
+ if(a[0]<b[0]) {return 1};
+ if(a[0]>b[0]) {return -1};
+ return 0;
+};
+
sorttable.innerSortFunction = function(tr) {
if(tr.classList.contains("sorttable_sorted"))
{
@@ -89,7 +96,7 @@ sorttable.innerSortFunction = function(tr) {
row_array[row_array.length] =
[ sorttable.getElementValue(rows[j].cells[col]), rows[j] ];
}
- row_array.sort().reverse();
+ row_array.sort(sorttable.compareFn);
tb = tr.sorttable_tbody;
row_array.forEach(function(row) { tb.appendChild(row[1]); });
tr.classList.add('sorttable_sorted');