added sorting functionality

This commit is contained in:
Felix Ivo
2025-06-16 10:56:45 +02:00
parent fd08f04600
commit e62a0ec2af
3 changed files with 280 additions and 26 deletions

View File

@@ -1,25 +1,5 @@
<?php include dirname(__DIR__).'/header.phtml'; ?>
<script>
document.querySelectorAll('.notes-table th[data-sort]').forEach(headerCell => {
headerCell.addEventListener('click', () => {
const sortBy = headerCell.dataset.sort;
const currentUrl = new URL(window.location.href);
const currentSortBy = currentUrl.searchParams.get('sort_by');
const currentSortOrder = currentUrl.searchParams.get('sort_order') || 'asc'; // Default to asc if not set
let newSortOrder = 'asc';
if (sortBy === currentSortBy && currentSortOrder.toLowerCase() === 'asc') {
newSortOrder = 'desc';
}
// If different column, or current is desc, start with asc for the new column
currentUrl.searchParams.set('sort_by', sortBy);
currentUrl.searchParams.set('sort_order', newSortOrder);
window.location.href = currentUrl.toString();
});
});
</script>
<?php include dirname(__DIR__).'/header.phtml'; ?>
<script src="JavaScript/script.js"></script>
<h2>Notes</h2>