Skip to content

Commit 2ffdb2f

Browse files
Progress on custom arrows pt1.
1 parent 327dfd1 commit 2ffdb2f

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

public/table-sort.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
/*
1+
/*
22
table-sort-js
33
Author: Lee Wannacott
4-
Licence: MIT License Copyright (c) 2021 Lee Wannacott
5-
4+
Licence: MIT License Copyright (c) 2021 Lee Wannacott
5+
66
GitHub Repository: https://github.com/LeeWannacott/table-sort-js
77
npm package: https://www.npmjs.com/package/table-sort-js
88
Demo: https://leewannacott.github.io/Portfolio/#/GitHub
99
Install:
1010
Frontend: <script src="https://leewannacott.github.io/table-sort-js/table-sort.js"></script> or
11-
Download this file and add <script src="table-sort.js"></script> to your HTML
12-
Backend: npm install table-sort-js and use require("../node_modules/table-sort-js/table-sort.js")
11+
Download this file and add <script src="table-sort.js"></script> to your HTML
12+
Backend: npm install table-sort-js and use require("../node_modules/table-sort-js/table-sort.js")
1313
Instructions:
1414
Add class="table-sort" to tables you'd like to make sortable
1515
Click on the table headers to sort them.
@@ -390,10 +390,10 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
390390
return sortAscending(b, a);
391391
}
392392

393-
function clearArrows(arrowUp, arrowDown, initialArrow = "↕") {
394-
th.innerHTML = th.innerHTML.replace(initialArrow, "");
395-
th.innerHTML = th.innerHTML.replace(arrowUp, "");
396-
th.innerHTML = th.innerHTML.replace(arrowDown, "");
393+
function clearArrows(arrow) {
394+
th.innerHTML = th.innerHTML.replace(arrow.neutral, "");
395+
th.innerHTML = th.innerHTML.replace(arrow.up, "");
396+
th.innerHTML = th.innerHTML.replace(arrow.down, "");
397397
}
398398

399399
if (column.toBeSorted[0] === undefined) {
@@ -402,7 +402,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
402402

403403
function changeTableArrow(arrowDirection) {
404404
if (table.hasClass.tableArrows) {
405-
clearArrows(arrow.up, arrow.down);
405+
clearArrows(arrow);
406406
th.insertAdjacentText("beforeend", arrowDirection);
407407
}
408408
}
@@ -524,12 +524,21 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
524524
columnIndexesClicked
525525
) {
526526
const desc = th.classList.contains("order-by-desc");
527-
const initialArrow = " ↕";
528-
const arrow = { up: " ↑", down: " ↓" };
529-
const fillValue = "!X!Y!Z!";
527+
const custom_arrows = th.classList.contains("custom-arrows");
528+
// for (let word in th.classList) {
529+
// console.log(word);
530+
// }
531+
let arrow = { neutral: " ↕", up: " ↑", down: " ↓" };
532+
let fillValue = "!X!Y!Z!";
533+
if (custom_arrows) {
534+
console.log(custom_arrows);
535+
console.log(custom_arrows.split("-"));
536+
[arrow.up, arrow.neutral, arrow.down] = custom_arrows.split();
537+
th.classList.add("table-arrows");
538+
}
530539

531540
if (table.hasClass.tableArrows) {
532-
th.insertAdjacentText("beforeend", initialArrow);
541+
th.insertAdjacentText("beforeend", arrow.neutral);
533542
}
534543

535544
let timesClickedColumn = 0;

src/test-table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class App extends Component {
8484
Statistics on public repositories pulled from the GitHub API v3:
8585
</h6>
8686
<div>
87-
<table className="table table-sort table-bordered table-responsive table-hover">
87+
<table className="table table-sort custom-arrows table-bordered table-responsive table-hover">
8888
<thead className="cw-light">
8989
<tr>
9090
<th>Repository Name</th>

0 commit comments

Comments
 (0)