Files

23 lines
805 B
TypeScript
Raw Permalink Normal View History

2022-12-23 17:03:11 +01:00
export function initTableSort() {
for (const header of document.querySelectorAll('th[data-sortt-asc]') || []) {
2025-12-03 03:13:16 +01:00
const sorttAsc = header.getAttribute('data-sortt-asc')!;
const sorttDesc = header.getAttribute('data-sortt-desc')!;
const sorttDefault = header.getAttribute('data-sortt-default')!;
header.addEventListener('click', () => {
tableSort(sorttAsc, sorttDesc, sorttDefault);
});
}
}
2025-01-22 08:11:51 +01:00
function tableSort(normSort: string, revSort: string, isDefault: string) {
2025-10-01 06:43:41 +02:00
if (!normSort) return;
if (!revSort) revSort = '';
2024-12-11 09:29:04 +01:00
const url = new URL(window.location.href);
let urlSort = url.searchParams.get('sort');
if (!urlSort && isDefault) urlSort = normSort;
url.searchParams.set('sort', urlSort !== normSort ? normSort : revSort);
window.location.replace(url.href);
}