Skip to content

Commit 8d5d500

Browse files
Support <th> tags in table rows. (#129)
1 parent cadb78f commit 8d5d500

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

browser-extensions/chrome/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33
"author": "Lee Wannacott",
44
"name": "table-sort-js",
5-
"version": "1.19.0",
5+
"version": "1.20.0",
66
"description": "Makes tables sortable using table-sort-js: https://github.com/LeeWannacott/table-sort-js",
77
"icons": { "48": "icons/t.png" },
88
"browser_action": {

browser-extensions/firefox/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"author": "Lee Wannacott",
44
"name": "table-sort-js",
5-
"version": "1.19.0",
5+
"version": "1.20.0",
66
"description": "Makes tables sortable using table-sort-js: https://github.com/LeeWannacott/table-sort-js",
77
"icons": { "48": "icons/t.png" },
88
"browser_action": {

npm/package.json

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

public/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h1>Manual testing of table sort js</h1>
1111
<tr>
1212
<td>Last Name</td>
1313
<td>First Name</td>
14-
<td class="order-by-desc">Birth Date</td>
14+
<th class="order-by-desc">Birth Date</th>
1515
<td>Employee ID</td>
1616
<td>Department</td>
1717
<td>Runtime</td>
@@ -21,7 +21,7 @@ <h1>Manual testing of table sort js</h1>
2121
<td>file version</td>
2222
</tr>
2323
<tr class="table-row-1">
24-
<td>Franklin</td>
24+
<th>Franklin</th>
2525
<td>Benjamin</td>
2626
<td>1706-1-17</td>
2727
<td>1</td>
@@ -33,7 +33,7 @@ <h1>Manual testing of table sort js</h1>
3333
<td>1.18.1</td>
3434
</tr>
3535
<tr class="table-row-2">
36-
<td>da Vinci</td>
36+
<th>da Vinci</th>
3737
<td>Zarlo</td>
3838
<td>1452-4-15</td>
3939
<td>13000</td>
@@ -45,7 +45,7 @@ <h1>Manual testing of table sort js</h1>
4545
<td>239.123.23</td>
4646
</tr>
4747
<tr>
48-
<td>Statham</td>
48+
<th>Statham</th>
4949
<td>Jason</td>
5050
<td>1967-7-26</td>
5151
<td></td>
@@ -57,7 +57,7 @@ <h1>Manual testing of table sort js</h1>
5757
<td>3423.342.34</td>
5858
</tr>
5959
<tr>
60-
<td>Micheal</td>
60+
<th>Micheal</th>
6161
<td>Angelo</td>
6262
<td>1958-8-21</td>
6363
<td>54</td>
@@ -70,7 +70,7 @@ <h1>Manual testing of table sort js</h1>
7070
</tr>
7171

7272
<tr>
73-
<td>Ben</td>
73+
<th>Ben</th>
7474
<td></td>
7575
<td>1994/9/23</td>
7676
<td>134</td>

public/table-sort.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
8282
break;
8383
}
8484
const tableColumn = tr
85-
.querySelectorAll("td")
85+
.querySelectorAll("* > th , * > td")
8686
.item(
8787
column.span[columnIndex] === 1
8888
? column.spanSum[columnIndex] - 1
@@ -125,11 +125,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
125125
headers: [],
126126
};
127127
for (let index of table.theads.keys()) {
128-
if (table.theads.item(index).querySelectorAll("th").length == 0) {
129-
table.headers.push(table.theads.item(index).querySelectorAll("td"));
130-
} else {
131-
table.headers.push(table.theads.item(index).querySelectorAll("th"));
132-
}
128+
table.headers.push(
129+
table.theads.item(index).querySelectorAll("* > th , * > td")
130+
);
133131
}
134132
for (let index of table.bodies.keys()) {
135133
if (table.bodies.item(index) == null) {
@@ -200,7 +198,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
200198
};
201199
const numberWithUnitType = /([.0-9]+)\s?(B|KB|KiB|MB|MiB|GB|GiB|TB|TiB)/i;
202200
for (let [i, tr] of table.visibleRows.entries()) {
203-
let fileSizeTd = tr.querySelectorAll("td").item(columnIndex).textContent;
201+
let fileSizeTd = tr
202+
.querySelectorAll("* > th , * > td")
203+
.item(columnIndex).textContent;
204204
let match = fileSizeTd.match(numberWithUnitType);
205205
if (match) {
206206
let number = parseFloat(match[1]);
@@ -465,7 +465,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
465465
"NaN"
466466
);
467467
}
468-
tr.querySelectorAll("td").item(columnIndex).innerHTML = fileSizeInBytesHTML;
468+
tr.querySelectorAll("* > th , * > td").item(columnIndex).innerHTML =
469+
fileSizeInBytesHTML;
469470
return table.hasClass.cellsSort ? tr.innerHTML : tr.outerHTML;
470471
}
471472

@@ -532,7 +533,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
532533
const column = {
533534
getColumn: function getColumn(tr, colSpanSum, colSpanData) {
534535
return tr
535-
.querySelectorAll("td")
536+
.querySelectorAll("* > th , * > td")
536537
.item(
537538
colSpanData[columnIndex] === 1
538539
? colSpanSum[columnIndex] - 1

0 commit comments

Comments
 (0)