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;