Added indicator to show if sorting is ascending or descending

This commit is contained in:
tracer 2022-10-26 11:58:27 +02:00
parent 8bc252ba4d
commit 4ed3dcd603

View File

@ -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;