diff --git a/public/index.html b/public/index.html
index 7ec7049..f9cc5c9 100644
--- a/public/index.html
+++ b/public/index.html
@@ -89,9 +89,8 @@
Testing table containing colspan and data-sort and multiple tbodies
On Our Dates |
First Sold Out |
-
-
+
|
Comedy |
Show 1 |
@@ -161,7 +160,6 @@ Testing table containing colspan and data-sort and multiple tbodies
50% |
2022-07-31 |
-
Last Name |
@@ -174,7 +172,7 @@ Testing table containing colspan and data-sort and multiple tbodies
data-sort days |
dates in dd/mm/yyyy |
-
+
Franklin |
Benjamin |
@@ -230,6 +228,7 @@ Testing table containing colspan and data-sort and multiple tbodies
Monday |
8/6/1978 |
+
Last Name |
@@ -242,7 +241,7 @@ Testing table containing colspan and data-sort and multiple tbodies
data-sort days |
dates in dd/mm/yyyy |
-
+
Franklin |
Benjamin |
diff --git a/public/table-sort.js b/public/table-sort.js
index a9a7e31..cd47d15 100644
--- a/public/table-sort.js
+++ b/public/table-sort.js
@@ -49,8 +49,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
if (sortableTable.getElementsByTagName("thead").length === 0) {
createMissingTableHead(sortableTable);
if (sortableTable.querySelectorAll("tbody").length > 1) {
- // Why index 1?; I don't remember
- return sortableTable.querySelectorAll("tbody")[1];
+ // don't select empty tbody that the browser creates
+ return sortableTable.querySelectorAll('tbody:not(:nth-child(2))');
} else {
return sortableTable.querySelectorAll("tbody");
}
@@ -85,8 +85,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
let foundMatch = false;
for (let key of Object.keys(inferableClasses)) {
let classRegexp = inferableClasses[key].regexp;
- if (tableColumn.innerText) {
- if (tableColumn.innerText.match(classRegexp) !== null) {
+ if (tableColumn?.innerText !== undefined) {
+ if (tableColumn.innerText.match(classRegexp)) {
foundMatch = true;
inferableClasses[key].count++;
}
@@ -114,21 +114,21 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
rows: [],
headers: [],
};
+ for (let index of table.theads.keys()) {
+ table.headers.push(table.theads.item(index).querySelectorAll("th"));
+ }
for (let index of table.bodies.keys()) {
if (table.bodies.item(index) == null) {
return;
}
- table.headers.push(table.theads.item(index).querySelectorAll("th"));
table.rows.push(table.bodies.item(index).querySelectorAll("tr"));
}
-
table.hasClass = {
noClassInfer: sortableTable.classList.contains("no-class-infer"),
cellsSort: sortableTable.classList.contains("cells-sort"),
tableArrows: sortableTable.classList.contains("table-arrows"),
rememberSort: sortableTable.classList.contains("remember-sort"),
};
-
for (
let headerIndex = 0;
headerIndex < table.theads.length;