Skip to content

Commit 20981a9

Browse files
When using table-arrows show arrows before clicking table headers; so it is less jarring.
1 parent e4e10c3 commit 20981a9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

public/table-sort.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function tableSortJs(test = false, domDocumentWindow = document) {
4040
if (sortableTable.getElementsByTagName("thead").length === 0) {
4141
if (test === true) {
4242
createTableHead = domDocumentWindow.createElement("thead");
43-
}else if (test === false) {
43+
} else if (test === false) {
4444
createTableHead = document.createElement("thead");
4545
}
4646
createTableHead.appendChild(sortableTable.rows[0]);
@@ -61,6 +61,16 @@ function tableSortJs(test = false, domDocumentWindow = document) {
6161
let columnIndexesClicked = [];
6262
for (let [columnIndex, th] of tableHeadHeaders.entries()) {
6363
let timesClickedColumn = 0;
64+
let desc = th.classList.contains("order-by-desc");
65+
let tableArrows = sortableTable.classList.contains("table-arrows");
66+
let arrowUp = " ▲";
67+
let arrowDown = " ▼";
68+
69+
if (desc && tableArrows) {
70+
th.insertAdjacentText("beforeend", arrowDown);
71+
} else if (tableArrows){
72+
th.insertAdjacentText("beforeend", arrowUp);
73+
}
6474

6575
th.addEventListener("click", function () {
6676
const tableRows = tableBody.querySelectorAll("tr");
@@ -347,17 +357,11 @@ function tableSortJs(test = false, domDocumentWindow = document) {
347357
th.innerText = th.innerText.replace(arrowDown, "");
348358
}
349359

350-
let arrowUp = " ▲";
351-
let arrowDown = " ▼";
352-
353360
// Sort naturally; default aescending unless th contains 'order-by-desc' as className.
354361
if (columnData[0] === undefined) {
355362
return;
356363
}
357364

358-
let desc = th.classList.contains("order-by-desc");
359-
let tableArrows = sortableTable.classList.contains("table-arrows");
360-
361365
if (timesClickedColumn === 1) {
362366
if (desc) {
363367
if (tableArrows) {

0 commit comments

Comments
 (0)