Admin sort

This commit is contained in:
2025-03-17 20:37:04 +00:00
parent 935e13d44b
commit 9e25f0023c

View File

@@ -20,6 +20,51 @@ require_db_auth();
row.classList.add("highlightJET"); // Add the class
}
});
// Sorting functionality
let table = document.querySelector("table");
let headers = table.querySelectorAll("th");
let sortDirection = {}; // Track sort direction for each column
headers.forEach((header, index) => {
header.addEventListener("click", function() {
let direction = sortDirection[index] === "asc" ? "desc" : "asc";
sortDirection[index] = direction;
sortTable(table, index, direction);
// Update visual indication
headers.forEach(h => h.classList.remove("sorted-asc", "sorted-desc"));
header.classList.add(direction === "asc" ? "sorted-asc" : "sorted-desc");
});
});
function sortTable(table, columnIndex, direction) {
let rows = Array.from(table.querySelectorAll("tbody tr"));
let isDate = !isNaN(Date.parse(rows[0].cells[columnIndex]?.textContent.trim() || ""));
let isNumeric = !isNaN(rows[0].cells[columnIndex]?.textContent.trim() || "");
let sortedRows = rows.sort((a, b) => {
let aText = a.cells[columnIndex]?.textContent.trim() || null;
let bText = b.cells[columnIndex]?.textContent.trim() || null;
if (aText === null || bText === null) {
return aText === null ? 1 : -1; // Place null/empty values at the bottom
}
if (isDate) {
let aDate = new Date(aText);
let bDate = new Date(bText);
return direction === "asc" ? aDate - bDate : bDate - aDate;
} else if (isNumeric) {
return direction === "asc" ? aText - bText : bText - aText;
} else {
return direction === "asc" ? aText.localeCompare(bText) : bText.localeCompare(aText);
}
});
let tbody = table.querySelector("tbody");
tbody.innerHTML = "";
sortedRows.forEach(row => tbody.appendChild(row));
}
});
</script>
<meta charset="UTF-8">
@@ -91,6 +136,16 @@ require_db_auth();
border-radius: 5px;
}
/* Add styles for sorted columns */
th.sorted-asc::after {
content: " ▲";
font-size: 0.8em;
}
th.sorted-desc::after {
content: " ▼";
font-size: 0.8em;
}
</style>
</head>
<body>
@@ -241,7 +296,6 @@ if ($result->num_rows > 0) {
echo '<td>' . htmlspecialchars($value ?? '') . '</td>';
}
}
echo '<td><img src="assets/cancel-icon.webp" title="Cancel PPR" style="width: 25px; height: auto;" onclick="markCancel(' . $row['id'] . ')"><img src="assets/cancel-icon.webp" title="DELETE PPR" style="width: 25px; height: auto;" onclick="deletePpr(' . $row['id'] . ')"><img src="assets/land.webp" title="Mark Landed" style="width: 30px; height: auto;" onclick="markLanded(' . $row['id'] . ')"></td>';
echo '</tr>';
}