keep sort order when changing the column, only revert in same colum

This commit is contained in:
tracer 2022-10-29 14:26:42 +02:00
parent 5a805aba07
commit c6c88456cf

View File

@ -98,16 +98,29 @@ function sortBy(column) {
document.getElementById(title).innerHTML = upCase(title) document.getElementById(title).innerHTML = upCase(title)
) )
// switch direction on every call console.log("col", column)
let currentTitleElement = document.getElementById(column) console.log("curcol", currentColumn)
let currentTitle = currentTitleElement.innerHTML
let newTitle if (currentColumn === column) {
console.log("in switch")
// switch direction on every call on same column
if (currentSortOrder === 'asc') { if (currentSortOrder === 'asc') {
currentSortOrder = 'desc' currentSortOrder = 'desc'
newTitle = currentTitle[0] + currentTitle.substring(1) + ' ⬇'
} else { } else {
currentSortOrder = 'asc' currentSortOrder = 'asc'
}
console.log("col", column)
} else {
currentColumn = column
}
let currentTitleElement = document.getElementById(column)
let currentTitle = currentTitleElement.innerHTML
let newTitle
if (currentSortOrder === 'asc') {
newTitle = currentTitle[0] + currentTitle.substring(1) + ' ⬇'
} else {
newTitle = currentTitle[0] + currentTitle.substring(1) + ' ⬆' newTitle = currentTitle[0] + currentTitle.substring(1) + ' ⬆'
} }
currentTitleElement.innerHTML = newTitle currentTitleElement.innerHTML = newTitle
@ -183,6 +196,7 @@ function closeError() {
// global scope // global scope
let currentSortOrder = 'desc' let currentSortOrder = 'desc'
let currentColumn = 'last'
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const table = document.getElementById('address_table') || false const table = document.getElementById('address_table') || false