From 8d5d500e484a24de4022f65db29df8a2fc936f4e Mon Sep 17 00:00:00 2001 From: Lee Wannacott Date: Fri, 15 Mar 2024 23:35:54 +1300 Subject: [PATCH] Support tags in table rows. (#129) --- browser-extensions/chrome/manifest.json | 2 +- browser-extensions/firefox/manifest.json | 2 +- npm/package.json | 2 +- public/index.html | 12 ++++++------ public/table-sort.js | 19 ++++++++++--------- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/browser-extensions/chrome/manifest.json b/browser-extensions/chrome/manifest.json index cec58b3..2f0fd4f 100644 --- a/browser-extensions/chrome/manifest.json +++ b/browser-extensions/chrome/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "author": "Lee Wannacott", "name": "table-sort-js", - "version": "1.19.0", + "version": "1.20.0", "description": "Makes tables sortable using table-sort-js: https://github.com/LeeWannacott/table-sort-js", "icons": { "48": "icons/t.png" }, "browser_action": { diff --git a/browser-extensions/firefox/manifest.json b/browser-extensions/firefox/manifest.json index 18a0122..c3fa018 100644 --- a/browser-extensions/firefox/manifest.json +++ b/browser-extensions/firefox/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "author": "Lee Wannacott", "name": "table-sort-js", - "version": "1.19.0", + "version": "1.20.0", "description": "Makes tables sortable using table-sort-js: https://github.com/LeeWannacott/table-sort-js", "icons": { "48": "icons/t.png" }, "browser_action": { diff --git a/npm/package.json b/npm/package.json index 0e03251..f4b887a 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "table-sort-js", - "version": "1.19.0", + "version": "1.20.0", "description": "A JavaScript client-side HTML table sorting library with no dependencies required.", "license": "MIT", "repository": "LeeWannacott/table-sort-js", diff --git a/public/index.html b/public/index.html index 1bb7799..e8b6483 100644 --- a/public/index.html +++ b/public/index.html @@ -11,7 +11,7 @@

Manual testing of table sort js

Last Name First Name - Birth Date + Birth Date Employee ID Department Runtime @@ -21,7 +21,7 @@

Manual testing of table sort js

file version - Franklin + Franklin Benjamin 1706-1-17 1 @@ -33,7 +33,7 @@

Manual testing of table sort js

1.18.1 - da Vinci + da Vinci Zarlo 1452-4-15 13000 @@ -45,7 +45,7 @@

Manual testing of table sort js

239.123.23 - Statham + Statham Jason 1967-7-26 @@ -57,7 +57,7 @@

Manual testing of table sort js

3423.342.34 - Micheal + Micheal Angelo 1958-8-21 54 @@ -70,7 +70,7 @@

Manual testing of table sort js

- Ben + Ben 1994/9/23 134 diff --git a/public/table-sort.js b/public/table-sort.js index 54aca82..300da8b 100644 --- a/public/table-sort.js +++ b/public/table-sort.js @@ -82,7 +82,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { break; } const tableColumn = tr - .querySelectorAll("td") + .querySelectorAll("* > th , * > td") .item( column.span[columnIndex] === 1 ? column.spanSum[columnIndex] - 1 @@ -125,11 +125,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { headers: [], }; for (let index of table.theads.keys()) { - if (table.theads.item(index).querySelectorAll("th").length == 0) { - table.headers.push(table.theads.item(index).querySelectorAll("td")); - } else { - table.headers.push(table.theads.item(index).querySelectorAll("th")); - } + table.headers.push( + table.theads.item(index).querySelectorAll("* > th , * > td") + ); } for (let index of table.bodies.keys()) { if (table.bodies.item(index) == null) { @@ -200,7 +198,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { }; const numberWithUnitType = /([.0-9]+)\s?(B|KB|KiB|MB|MiB|GB|GiB|TB|TiB)/i; for (let [i, tr] of table.visibleRows.entries()) { - let fileSizeTd = tr.querySelectorAll("td").item(columnIndex).textContent; + let fileSizeTd = tr + .querySelectorAll("* > th , * > td") + .item(columnIndex).textContent; let match = fileSizeTd.match(numberWithUnitType); if (match) { let number = parseFloat(match[1]); @@ -465,7 +465,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { "NaN" ); } - tr.querySelectorAll("td").item(columnIndex).innerHTML = fileSizeInBytesHTML; + tr.querySelectorAll("* > th , * > td").item(columnIndex).innerHTML = + fileSizeInBytesHTML; return table.hasClass.cellsSort ? tr.innerHTML : tr.outerHTML; } @@ -532,7 +533,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { const column = { getColumn: function getColumn(tr, colSpanSum, colSpanData) { return tr - .querySelectorAll("td") + .querySelectorAll("* > th , * > td") .item( colSpanData[columnIndex] === 1 ? colSpanSum[columnIndex] - 1