@@ -105,41 +105,46 @@ document.addEventListener("DOMContentLoaded", function() {
105
105
106
106
function addSortButton ( el , idx ) {
107
107
const button = document . createElement ( 'button' ) ;
108
- if ( idx === 0 || idx === 5 || idx === 6 ) {
109
- button . innerText = 'Sort' ;
110
- button . addEventListener ( "click" , function ( ) {
111
- sortTable ( idx ) ;
112
- } ) ;
113
- button . setAttribute ( 'style' , 'justify-content: center' ) ;
114
- }
108
+ const img = document . createElement ( 'img' ) ;
109
+ button . innerText = 'Sort' ;
110
+ button . addEventListener ( "click" , function ( ) {
111
+ sortTable ( idx ) ;
112
+ } ) ;
113
+ img . addEventListener ( "click" , function ( ) {
114
+ sortTable ( idx ) ;
115
+ } ) ;
116
+ button . setAttribute ( 'style' , 'justify-content: center' ) ;
117
+
115
118
el . appendChild ( button ) ;
116
119
}
117
120
118
121
let direction = false ;
119
122
function sortTable ( columnIndex ) {
120
123
removeAllChildNodes ( tbody ) ;
121
- if ( columnIndex === 0 ) {
124
+ if ( isNaN ( rows [ 0 ] . columns [ columnIndex ] [ 0 ] ) && isNaN ( rows [ rows . length - 1 ] . columns [ columnIndex ] [ 0 ] ) ) {
122
125
rows . sort ( ( a , b ) => {
123
- a = a . columns [ columnIndex ] . split ( "-" ) ;
124
- b = b . columns [ columnIndex ] . split ( "-" ) ;
125
- if ( a [ 0 ] === b [ 0 ] ) {
126
- return direction ? a [ 1 ] - b [ 1 ] : b [ 1 ] - a [ 1 ] ;
127
- } else {
128
- return direction ? a [ 0 ] - b [ 0 ] : b [ 0 ] - a [ 0 ] ;
129
- }
126
+ a = a . columns [ columnIndex ] ;
127
+ b = b . columns [ columnIndex ] ;
128
+ return direction ? a . localeCompare ( b ) : b . localeCompare ( a ) ;
130
129
} ) ;
131
-
132
- for ( let i = 0 ; i <= rows . length - 1 ; i ++ ) {
133
- tbody . appendChild ( rows [ i ] . el ) ;
134
- }
135
130
} else {
136
- rows . sort ( ( a , b ) => {
137
- return direction ? a . columns [ columnIndex ] - b . columns [ columnIndex ] : b . columns [ columnIndex ] - a . columns [ columnIndex ] ;
138
- } ) ;
139
- for ( let i = 0 ; i <= rows . length - 1 ; i ++ ) {
140
- tbody . appendChild ( rows [ i ] . el ) ;
131
+ if ( ! columnIndex && window . location . href . includes ( "docs/alerts" ) ) {
132
+ rows . sort ( ( a , b ) => {
133
+ a = a . columns [ columnIndex ] . split ( "-" ) ;
134
+ b = b . columns [ columnIndex ] . split ( "-" ) ;
135
+ return direction ? a [ 0 ] - b [ 0 ] : b [ 0 ] - a [ 0 ] ;
136
+ } ) ;
137
+ } else {
138
+ rows . sort ( ( a , b ) => {
139
+ a = a . columns [ columnIndex ] ;
140
+ b = b . columns [ columnIndex ] ;
141
+ return direction ? a - b : b - a ;
142
+ } ) ;
141
143
}
142
144
}
145
+ for ( let i = 0 ; i <= rows . length - 1 ; i ++ ) {
146
+ tbody . appendChild ( rows [ i ] . el ) ;
147
+ }
143
148
direction = ! direction ;
144
149
}
145
150
0 commit comments