From 8e0a2ff6e82250fca04a182cac570c9efba5c207 Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 25 Oct 2022 18:25:38 +0200 Subject: [PATCH] every click on a column title changes the sort order --- public/assets/js/functions.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/public/assets/js/functions.js b/public/assets/js/functions.js index 058fe5b..08bd628 100644 --- a/public/assets/js/functions.js +++ b/public/assets/js/functions.js @@ -80,6 +80,15 @@ function deleteAddress(id) { function sortBy(column) { console.log("sortby: " + column) + // switch direction on every call + let currentSortOrder = document.getElementById(column + '_sort') + let sortOrder = 0 + if (currentSortOrder.innerHTML === 'asc') { + currentSortOrder.innerHTML = 'desc' + } else { + currentSortOrder.innerHTML = 'asc' + } + const table = document.getElementById('address_table'); let dirty = true; // loop until clean @@ -102,7 +111,15 @@ function sortBy(column) { console.log(valueX, valueY) // mind asc & desc - let sortOrder = 1 + + let currentSortOrder = document.getElementById(column + '_sort') + let sortOrder = 0 + if (currentSortOrder.innerHTML === 'asc') { + sortOrder = 1 + } else { + sortOrder = -1 + } + console.log("cs", currentSortOrder.innerHTML) console.log(valueX.localeCompare(valueY)) if (valueX.localeCompare(valueY) === sortOrder) {