1
- /*
1
+ /*
2
2
table-sort-js
3
3
Author: Lee Wannacott
4
- Licence: MIT License Copyright (c) 2021 Lee Wannacott
5
-
4
+ Licence: MIT License Copyright (c) 2021 Lee Wannacott
5
+
6
6
GitHub Repository: https://github.com/LeeWannacott/table-sort-js
7
7
npm package: https://www.npmjs.com/package/table-sort-js
8
8
Demo: https://leewannacott.github.io/Portfolio/#/GitHub
9
9
Install:
10
10
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")
13
13
Instructions:
14
14
Add class="table-sort" to tables you'd like to make sortable
15
15
Click on the table headers to sort them.
@@ -390,10 +390,10 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
390
390
return sortAscending ( b , a ) ;
391
391
}
392
392
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 , "" ) ;
397
397
}
398
398
399
399
if ( column . toBeSorted [ 0 ] === undefined ) {
@@ -402,7 +402,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
402
402
403
403
function changeTableArrow ( arrowDirection ) {
404
404
if ( table . hasClass . tableArrows ) {
405
- clearArrows ( arrow . up , arrow . down ) ;
405
+ clearArrows ( arrow ) ;
406
406
th . insertAdjacentText ( "beforeend" , arrowDirection ) ;
407
407
}
408
408
}
@@ -524,12 +524,21 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
524
524
columnIndexesClicked
525
525
) {
526
526
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
+ }
530
539
531
540
if ( table . hasClass . tableArrows ) {
532
- th . insertAdjacentText ( "beforeend" , initialArrow ) ;
541
+ th . insertAdjacentText ( "beforeend" , arrow . neutral ) ;
533
542
}
534
543
535
544
let timesClickedColumn = 0 ;
0 commit comments