@@ -328,19 +328,25 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
328
328
329
329
th . addEventListener ( "click" , function ( ) {
330
330
const columnData = [ ] ;
331
- const tableRows = tableBody . querySelectorAll ( "tr" ) ;
331
+ // To make it work even if there is a tr with display: none; in the table, only the tr that is currently displayed is subject to sorting.
332
+ const visibleTableRows = Array . prototype . filter . call (
333
+ tableBody . querySelectorAll ( "tr" ) ,
334
+ ( tr ) => {
335
+ return tr . style . display !== "none" ;
336
+ }
337
+ ) ;
332
338
333
339
let isDataAttribute = th . classList . contains ( "data-sort" ) ;
334
340
// Check if using data-sort attribute; if so sort by value of data-sort
335
341
// attribute.
336
342
if ( isDataAttribute ) {
337
- sortDataAttributes ( tableRows , columnData ) ;
343
+ sortDataAttributes ( visibleTableRows , columnData ) ;
338
344
}
339
345
340
346
let isFileSize = th . classList . contains ( "file-size" ) ;
341
347
// Handle filesize sorting (e.g KB, MB, GB, TB) - Turns data into KiB.
342
348
if ( isFileSize ) {
343
- sortFileSize ( tableRows , columnData ) ;
349
+ sortFileSize ( visibleTableRows , columnData ) ;
344
350
}
345
351
346
352
// Checking if user has clicked different column from the first column if
@@ -352,8 +358,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
352
358
353
359
timesClickedColumn += 1 ;
354
360
355
- getTableData ( tableRows , columnData , isFileSize , isDataAttribute ) ;
356
- updateTable ( tableRows , columnData , isFileSize ) ;
361
+ getTableData ( visibleTableRows , columnData , isFileSize , isDataAttribute ) ;
362
+ updateTable ( visibleTableRows , columnData , isFileSize ) ;
357
363
} ) ;
358
364
}
359
365
}
0 commit comments