@@ -1325,13 +1325,48 @@ <h3 id="spotweb-indexers">Spotweb Indexers</h3>
1325
1325
1326
1326
< a href ="#top "> Back to top</ a >
1327
1327
1328
- < script >
1329
- document . addEventListener ( 'DOMContentLoaded' , ( ) => {
1330
- new Tablesort ( document . getElementById ( 'table-1' ) ) ;
1331
- new Tablesort ( document . getElementById ( 'table-2' ) ) ;
1332
- new Tablesort ( document . getElementById ( 'table-3' ) ) ;
1328
+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.2.1/tablesort.min.js "> </ script >
1329
+ < script >
1330
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
1331
+ // Initialize Tablesort for each table
1332
+ new Tablesort ( document . getElementById ( 'table-1' ) ) ;
1333
+ new Tablesort ( document . getElementById ( 'table-2' ) ) ;
1334
+ new Tablesort ( document . getElementById ( 'table-3' ) ) ;
1335
+ } ) ;
1336
+
1337
+ // Extend Tablesort to support custom sorting
1338
+ Tablesort . extend ( 'data-group' , function ( item ) {
1339
+ return item . getAttribute ( 'data-group' ) || item . innerText ;
1340
+ } ) ;
1341
+
1342
+ // Custom function to sort table and keep groups together
1343
+ function sortTable ( tableId , columnIndex ) {
1344
+ const table = document . getElementById ( tableId ) ;
1345
+ const tbody = table . querySelector ( 'tbody' ) ;
1346
+ const rows = Array . from ( tbody . querySelectorAll ( 'tr' ) ) ;
1347
+
1348
+ // Create a map of group to rows
1349
+ const groups = rows . reduce ( ( acc , row ) => {
1350
+ const group = row . getAttribute ( 'data-group' ) || row . rowIndex ;
1351
+ if ( ! acc [ group ] ) acc [ group ] = [ ] ;
1352
+ acc [ group ] . push ( row ) ;
1353
+ return acc ;
1354
+ } , { } ) ;
1355
+
1356
+ // Get groups in sorted order based on the first row of each group
1357
+ const sortedGroups = Object . keys ( groups ) . sort ( ( a , b ) => {
1358
+ const cellA = groups [ a ] [ 0 ] . cells [ columnIndex ] . innerText . toLowerCase ( ) ;
1359
+ const cellB = groups [ b ] [ 0 ] . cells [ columnIndex ] . innerText . toLowerCase ( ) ;
1360
+ return cellA . localeCompare ( cellB ) ;
1361
+ } ) ;
1362
+
1363
+ // Append rows to tbody in sorted order
1364
+ tbody . innerHTML = '' ;
1365
+ sortedGroups . forEach ( group => {
1366
+ groups [ group ] . forEach ( row => tbody . appendChild ( row ) ) ;
1333
1367
} ) ;
1334
- </ script >
1368
+ }
1369
+ </ script >
1335
1370
1336
1371
1337
1372
</ body >
0 commit comments