1
+ /* eslint-disable max-len */
2
+ /* eslint-disable no-trailing-spaces */
3
+ /* eslint-disable indent */
1
4
// JS Goes here - ES6 supported
2
5
3
6
import "./css/main.css" ;
@@ -53,6 +56,9 @@ document.addEventListener("DOMContentLoaded", function() {
53
56
54
57
// Add input for filtering
55
58
function addInput ( el , label , idx ) {
59
+ const container = document . createElement ( 'div' ) ;
60
+ container . setAttribute ( 'style' , 'display: flex; align-items: center;' ) ;
61
+
56
62
const input = document . createElement ( 'input' ) ;
57
63
input . addEventListener ( "change" , function ( e ) {
58
64
widget . filters [ idx ] = e . target . value ;
@@ -65,7 +71,11 @@ document.addEventListener("DOMContentLoaded", function() {
65
71
input . setAttribute ( 'type' , 'text' ) ;
66
72
input . setAttribute ( 'name' , 'filter_' + label ) ;
67
73
input . setAttribute ( 'list' , 'opts_for_' + label ) ;
68
- el . appendChild ( input ) ;
74
+
75
+ container . appendChild ( input ) ;
76
+ addSortButton ( container , idx ) ;
77
+
78
+ el . appendChild ( container ) ;
69
79
}
70
80
const tbody = el . querySelector ( 'tbody' ) ;
71
81
const headings = Array . from ( el . querySelectorAll ( 'thead th' ) ) . map ( ( el , idx ) => {
@@ -95,6 +105,47 @@ document.addEventListener("DOMContentLoaded", function() {
95
105
} ;
96
106
} ) ;
97
107
108
+ function addSortButton ( el , idx ) {
109
+ const img = document . createElement ( 'img' ) ;
110
+ img . src = "/img/up-down-arrows-icon.png"
111
+ img . addEventListener ( "click" , function ( ) {
112
+ sortTable ( idx ) ;
113
+ } ) ;
114
+ img . setAttribute ( 'style' , 'width: 16px; margin-left: 5px' )
115
+
116
+ el . appendChild ( img )
117
+ }
118
+
119
+ let direction = false ;
120
+ function sortTable ( columnIndex ) {
121
+ removeAllChildNodes ( tbody ) ;
122
+ if ( isNaN ( rows [ 0 ] . columns [ columnIndex ] [ 0 ] ) && isNaN ( rows [ rows . length - 1 ] . columns [ columnIndex ] [ 0 ] ) ) {
123
+ rows . sort ( ( a , b ) => {
124
+ a = a . columns [ columnIndex ] ;
125
+ b = b . columns [ columnIndex ] ;
126
+ return direction ? a . localeCompare ( b ) : b . localeCompare ( a ) ;
127
+ } ) ;
128
+ } else {
129
+ if ( ! columnIndex && window . location . href . includes ( "docs/alerts" ) ) {
130
+ rows . sort ( ( a , b ) => {
131
+ a = a . columns [ columnIndex ] . split ( "-" ) ;
132
+ b = b . columns [ columnIndex ] . split ( "-" ) ;
133
+ return direction ? a [ 0 ] - b [ 0 ] : b [ 0 ] - a [ 0 ] ;
134
+ } ) ;
135
+ } else {
136
+ rows . sort ( ( a , b ) => {
137
+ a = a . columns [ columnIndex ] ;
138
+ b = b . columns [ columnIndex ] ;
139
+ return direction ? a - b : b - a ;
140
+ } ) ;
141
+ }
142
+ }
143
+ for ( let i = 0 ; i <= rows . length - 1 ; i ++ ) {
144
+ tbody . appendChild ( rows [ i ] . el ) ;
145
+ }
146
+ direction = ! direction ;
147
+ }
148
+
98
149
// Go through options elements and populate lists with column aggregates
99
150
// gathered in previous loop
100
151
Object . entries ( widget . options ) . map ( pair => {
0 commit comments