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