(column)
| 1233 | let currentSort = { column: null, ascending: true }; |
| 1234 | |
| 1235 | function sortTable(column) { |
| 1236 | // Toggle sort order if clicking the same column |
| 1237 | if (currentSort.column === column) { |
| 1238 | currentSort.ascending = !currentSort.ascending; |
| 1239 | } else { |
| 1240 | currentSort.column = column; |
| 1241 | currentSort.ascending = true; |
| 1242 | } |
| 1243 | |
| 1244 | const rows = Array.from(document.querySelectorAll(".game-row")); |
| 1245 | |
| 1246 | // Comparison function based on selected column |
| 1247 | function compareRows(a, b) { |
| 1248 | let aValue, bValue; |
| 1249 | |
| 1250 | if (column === "name") { |
| 1251 | // For name sorting, use just the folder name (not full path) |
| 1252 | aValue = a.dataset.path.split("/").pop() || ""; |
| 1253 | bValue = b.dataset.path.split("/").pop() || ""; |
| 1254 | return currentSort.ascending |
| 1255 | ? aValue.localeCompare(bValue) |
| 1256 | : bValue.localeCompare(aValue); |
| 1257 | } else if (column === "date") { |
| 1258 | // Get timestamps, treat empty/missing as 0 (will sort to the end when ascending) |
| 1259 | aValue = parseInt(a.dataset.timestamp) || 0; |
| 1260 | bValue = parseInt(b.dataset.timestamp) || 0; |
| 1261 | |
| 1262 | // Put entries without timestamps at the end |
| 1263 | if (aValue === 0 && bValue === 0) return 0; |
| 1264 | if (aValue === 0) return 1; |
| 1265 | if (bValue === 0) return -1; |
| 1266 | |
| 1267 | return currentSort.ascending ? aValue - bValue : bValue - aValue; |
| 1268 | } |
| 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | // Sort all rows |
| 1274 | rows.sort(compareRows); |
| 1275 | |
| 1276 | // Get the table header element |
| 1277 | const tableHeader = document.querySelector(".table-header"); |
| 1278 | |
| 1279 | // Remove all existing rows |
| 1280 | rows.forEach((row) => row.remove()); |
| 1281 | |
| 1282 | // Re-insert rows in sorted order |
| 1283 | let previousElement = tableHeader; |
| 1284 | rows.forEach((row) => { |
| 1285 | previousElement.after(row); |
| 1286 | previousElement = row; |
| 1287 | }); |
| 1288 | |
| 1289 | // Re-apply filters to maintain visibility state |
| 1290 | applyFilters(); |
| 1291 | } |
nothing calls this directly
no test coverage detected