Skip to content

Commit c7d0853

Browse files
Update npm package to 1.6.9.
1 parent 8d3546e commit c7d0853

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

npm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "table-sort-js",
3-
"version": "1.6.8",
3+
"version": "1.6.9",
44
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.",
55
"license": "MIT",
66
"repository": "LeeWannacott/table-sort-js",

npm/table-sort.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -328,19 +328,25 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
328328

329329
th.addEventListener("click", function () {
330330
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+
);
332338

333339
let isDataAttribute = th.classList.contains("data-sort");
334340
// Check if using data-sort attribute; if so sort by value of data-sort
335341
// attribute.
336342
if (isDataAttribute) {
337-
sortDataAttributes(tableRows, columnData);
343+
sortDataAttributes(visibleTableRows, columnData);
338344
}
339345

340346
let isFileSize = th.classList.contains("file-size");
341347
// Handle filesize sorting (e.g KB, MB, GB, TB) - Turns data into KiB.
342348
if (isFileSize) {
343-
sortFileSize(tableRows, columnData);
349+
sortFileSize(visibleTableRows, columnData);
344350
}
345351

346352
// Checking if user has clicked different column from the first column if
@@ -352,8 +358,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
352358

353359
timesClickedColumn += 1;
354360

355-
getTableData(tableRows, columnData, isFileSize, isDataAttribute);
356-
updateTable(tableRows, columnData, isFileSize);
361+
getTableData(visibleTableRows, columnData, isFileSize, isDataAttribute);
362+
updateTable(visibleTableRows, columnData, isFileSize);
357363
});
358364
}
359365
}

0 commit comments

Comments
 (0)