diff --git a/public/index.html b/public/index.html index f9cc5c9..b50d9a3 100644 --- a/public/index.html +++ b/public/index.html @@ -87,18 +87,20 @@

Testing table containing colspan and data-sort and multiple tbodies

Show Overall On Our Dates + On Our Dates First Sold Out Comedy - Show 1 + 1 18/25 72% 3/4 75% - 1999-07-30 + 2 + 1999-7-30 @@ -107,8 +109,9 @@

Testing table containing colspan and data-sort and multiple tbodies

6/10 60% 3/4 + 8 75% - 1999-08-04 + 1999-8-04 @@ -118,47 +121,52 @@

Testing table containing colspan and data-sort and multiple tbodies

47% 3/4 75% - 1999-07-19 + 2.12 + 1999-7-19 Comedy - Show 4 + 4 10/15 67% 2/3 67% - 1999-07-19 + 2.13 + 1999-7-19 Comedy - Show 5 + 5 9/12 75% 1/2 50% - 1999-07-29 + 2.83 + 1999-7-29 Comedy - Show 6 + 6 16/24 67% 2/4 50% - 1999-07-26 + 2.83 + 1999-7-26 Comedy - Show 7 + 7 16/26 62% 2/4 50% - 2022-07-31 + 2.03 + 2022-7-31 diff --git a/public/table-sort.js b/public/table-sort.js index 6894229..52ccf16 100644 --- a/public/table-sort.js +++ b/public/table-sort.js @@ -54,7 +54,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { } } - function inferSortClasses(tableRows, columnIndex, th) { + function inferSortClasses(tableRows, columnIndex, column, th) { const runtimeRegex = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i; const fileSizeRegex = /^([.0-9]+)\s?(B|KB|KiB|MB|MiB|GB|GiB|TB|TiB)/i; // Doesn't infer dates with delimiter "."; as could capture semantic version numbers. @@ -75,7 +75,13 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { if (regexNotFoundCount >= threshold) { break; } - const tableColumn = tr.querySelectorAll("td").item(columnIndex); + const tableColumn = tr + .querySelectorAll("td") + .item( + column.span[columnIndex] === 1 + ? column.spanSum[columnIndex] - 1 + : column.spanSum[columnIndex] - column.span[columnIndex] + ); let foundMatch = false; for (let key of Object.keys(inferableClasses)) { let classRegexp = inferableClasses[key].regexp; @@ -129,11 +135,13 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { headerIndex++ ) { let columnIndexesClicked = []; + const column = { span: {}, spanSum: {} }; + getColSpanData(table.headers[headerIndex], column); for (let [columnIndex, th] of table.headers[headerIndex].entries()) { if (!th.classList.contains("disable-sort")) { th.style.cursor = "pointer"; if (!table.hasClass.noClassInfer) { - inferSortClasses(table.rows[headerIndex], columnIndex, th); + inferSortClasses(table.rows[headerIndex], columnIndex, column, th); } makeEachColumnSortable( th, @@ -416,13 +424,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { template.innerHTML = columnIndexAndTableRow[column.toBeSorted[i]]; tr = template.content.firstChild; } - let getColumnTd = column.getColumn( - tr, - column.spanSum, - column.span - ); - let fileSizeInBytesHTML = getColumnTd.outerHTML - const fileSizeInBytesText = getColumnTd.textContent + let getColumnTd = column.getColumn(tr, column.spanSum, column.span); + let fileSizeInBytesHTML = getColumnTd.outerHTML; + const fileSizeInBytesText = getColumnTd.textContent; const fileSize = column.toBeSorted[i].replace(/#[0-9]*/, ""); let prefixes = ["", "Ki", "Mi", "Gi", "Ti", "Pi"]; let replaced = false;