Skip to content

Commit

Permalink
Support <th> tags in table rows. (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeWannacott committed Mar 15, 2024
1 parent cadb78f commit 8d5d500
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion browser-extensions/chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion browser-extensions/firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 6 additions & 6 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1>Manual testing of table sort js</h1>
<tr>
<td>Last Name</td>
<td>First Name</td>
<td class="order-by-desc">Birth Date</td>
<th class="order-by-desc">Birth Date</th>
<td>Employee ID</td>
<td>Department</td>
<td>Runtime</td>
Expand All @@ -21,7 +21,7 @@ <h1>Manual testing of table sort js</h1>
<td>file version</td>
</tr>
<tr class="table-row-1">
<td>Franklin</td>
<th>Franklin</th>
<td>Benjamin</td>
<td>1706-1-17</td>
<td>1</td>
Expand All @@ -33,7 +33,7 @@ <h1>Manual testing of table sort js</h1>
<td>1.18.1</td>
</tr>
<tr class="table-row-2">
<td>da Vinci</td>
<th>da Vinci</th>
<td>Zarlo</td>
<td>1452-4-15</td>
<td>13000</td>
Expand All @@ -45,7 +45,7 @@ <h1>Manual testing of table sort js</h1>
<td>239.123.23</td>
</tr>
<tr>
<td>Statham</td>
<th>Statham</th>
<td>Jason</td>
<td>1967-7-26</td>
<td></td>
Expand All @@ -57,7 +57,7 @@ <h1>Manual testing of table sort js</h1>
<td>3423.342.34</td>
</tr>
<tr>
<td>Micheal</td>
<th>Micheal</th>
<td>Angelo</td>
<td>1958-8-21</td>
<td>54</td>
Expand All @@ -70,7 +70,7 @@ <h1>Manual testing of table sort js</h1>
</tr>

<tr>
<td>Ben</td>
<th>Ben</th>
<td></td>
<td>1994/9/23</td>
<td>134</td>
Expand Down
19 changes: 10 additions & 9 deletions public/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8d5d500

Please sign in to comment.