Skip to content

Commit 06f5c3a

Browse files
committed
Better handling of tables without theads
1 parent 474648e commit 06f5c3a

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

js/install.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
var options = INSTALL_OPTIONS;
33

44
Array.prototype.forEach.call(document.querySelectorAll('table'), function(table){
5+
try {
6+
// If there’s no tHead but the first tBody row contains ths, create a tHead and move that row into it.
7+
if (!table.tHead && (var firstTBodyRow = table.tBodies[0].rows[0]).children[0].tagName === 'TH') {
8+
var tHead = document.createElement('thead');
9+
tHead.appendChild(firstTBodyRow);
10+
table.insertBefore(tHead, table.firstChild);
11+
}
12+
13+
// Sortable requires this
14+
if (table.tHead.rows.length !== 1) {
15+
return;
16+
}
17+
} catch (err) {
18+
return;
19+
}
20+
521
table.setAttribute('data-sortable', '');
622
table.classList.add('sortable-theme-' + options.theme);
723
});

0 commit comments

Comments
 (0)