From 4ed3dcd603f342529d7767ef3c5710b68e05830c Mon Sep 17 00:00:00 2001 From: tracer Date: Wed, 26 Oct 2022 11:58:27 +0200 Subject: [PATCH] Added indicator to show if sorting is ascending or descending --- public/assets/js/functions.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/public/assets/js/functions.js b/public/assets/js/functions.js index 9e28e51..9f21fae 100644 --- a/public/assets/js/functions.js +++ b/public/assets/js/functions.js @@ -73,14 +73,30 @@ function deleteAddress(id) { } } +function upCase(text) { + return text[0].toUpperCase() + text.substring(1); +} function sortBy(column) { + // clear titles + const titles = ['first', 'last', 'street', 'zip', 'city', 'phone'] + titles.forEach((title) => + document.getElementById(title).innerHTML = upCase(title) + ) + // switch direction on every call - let currentSortOrder = document.getElementById(column + '_sort') + let currentSortOrder = document.getElementById(column + '_sort') + let currentTitleElement = document.getElementById(column) + let currentTitle = currentTitleElement.innerHTML + + let newTitle = '' if (currentSortOrder.innerHTML === 'asc') { currentSortOrder.innerHTML = 'desc' + newTitle = currentTitle[0] + currentTitle.substring(1) + ' ⬇' } else { currentSortOrder.innerHTML = 'asc' + newTitle = currentTitle[0] + currentTitle.substring(1) + ' ⬆' } + currentTitleElement.innerHTML = newTitle const table = document.getElementById('address_table'); let dirty = true;