1- /*
1+ /*
22table-sort-js
33Author: Lee Wannacott
4- Licence: MIT License Copyright (c) 2021 Lee Wannacott
5-
4+ Licence: MIT License Copyright (c) 2021 Lee Wannacott
5+
66GitHub Repository: https://github.com/LeeWannacott/table-sort-js
77npm package: https://www.npmjs.com/package/table-sort-js
88Demo: https://leewannacott.github.io/Portfolio/#/GitHub
99Install:
1010Frontend: <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")
1313Instructions:
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 ;
0 commit comments