Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple thead from tbodies. #112

Merged
merged 3 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ <h2>Testing table containing colspan and data-sort and multiple tbodies</h2>
<th colspan="2" class="data-sort">On Our Dates</th>
<th>First Sold Out</th>
</tr>
</thead>
<tbody>
<tr>
</thead>
<td class="tags"></td>
<td class="category">Comedy</td>
<td class="show_name">Show 1</td>
Expand Down Expand Up @@ -161,7 +160,6 @@ <h2>Testing table containing colspan and data-sort and multiple tbodies</h2>
<td class="pct ours">50%</td>
<td>2022-07-31</td>
</tr>
</tbody>
<thead>
<tr>
<th>Last Name</th>
Expand All @@ -174,7 +172,7 @@ <h2>Testing table containing colspan and data-sort and multiple tbodies</h2>
<th class="data-sort">data-sort days</th>
<th>dates in dd/mm/yyyy</th>
</tr>
</thead>
</thead>
<tr class="table-row-1">
<td>Franklin</td>
<td>Benjamin</td>
Expand Down Expand Up @@ -230,6 +228,7 @@ <h2>Testing table containing colspan and data-sort and multiple tbodies</h2>
<td data-sort="1">Monday</td>
<td>8/6/1978</td>
</tr>
</tbody>
<thead>
<tr>
<th>Last Name</th>
Expand All @@ -242,7 +241,7 @@ <h2>Testing table containing colspan and data-sort and multiple tbodies</h2>
<th class="data-sort">data-sort days</th>
<th>dates in dd/mm/yyyy</th>
</tr>
</thead>
</thead>
<tr class="table-row-1">
<td>Franklin</td>
<td>Benjamin</td>
Expand Down
14 changes: 7 additions & 7 deletions public/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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;
Expand Down