table-sort-js
Advanced tools
Comparing version 1.9.2 to 1.10.2
{ | ||
"name": "table-sort-js", | ||
"version": "1.9.2", | ||
"version": "1.10.2", | ||
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -54,6 +54,7 @@ ![table-sort-js](https://img.shields.io/npm/v/table-sort-js) | ||
| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g <td data-sort="42"> | | ||
| "onload-sort" | Sort column on loading of the page. Simulates a click from the user. (can only sort onload for one column) | | ||
| "file-size-sort" | Sort file sizes(B->TiB) uses the binary prefix. (e.g KiB) | | ||
| "disable-sort" | Disallow sorting the table by this specific column. | | ||
| "alpha-sort" | Sort alphabetically (z11,z2); default is [natural sort](https://en.wikipedia.org/wiki/Natural_sort_order) (z2,z11). | | ||
| "punct-sort" | Sort punctuation; default ignores punctuation. | | ||
| "disable-sort" | Disallow sorting the table by this specific column. | | ||
@@ -60,0 +61,0 @@ #### Development: |
@@ -38,22 +38,28 @@ /* | ||
function makeTableSortable(sortableTable) { | ||
function createMissingTableHead(sortableTable) { | ||
let createTableHead; | ||
let tableBody; | ||
if (testingTableSortJS === true) { | ||
createTableHead = domDocumentWindow.createElement("thead"); | ||
} else { | ||
createTableHead = document.createElement("thead"); | ||
} | ||
createTableHead.appendChild(sortableTable.rows[0]); | ||
sortableTable.insertBefore(createTableHead, sortableTable.firstChild); | ||
} | ||
function getTableBody(sortableTable) { | ||
if (sortableTable.getElementsByTagName("thead").length === 0) { | ||
if (testingTableSortJS === true) { | ||
createTableHead = domDocumentWindow.createElement("thead"); | ||
} else { | ||
createTableHead = document.createElement("thead"); | ||
} | ||
createTableHead.appendChild(sortableTable.rows[0]); | ||
sortableTable.insertBefore(createTableHead, sortableTable.firstChild); | ||
createMissingTableHead(sortableTable); | ||
if (sortableTable.querySelectorAll("tbody").length > 1) { | ||
tableBody = sortableTable.querySelectorAll("tbody")[1]; | ||
return sortableTable.querySelectorAll("tbody")[1]; | ||
} else { | ||
tableBody = sortableTable.querySelector("tbody"); | ||
return sortableTable.querySelector("tbody"); | ||
} | ||
} else { | ||
tableBody = sortableTable.querySelector("tbody"); | ||
return sortableTable.querySelector("tbody"); | ||
} | ||
} | ||
function makeTableSortable(sortableTable) { | ||
const tableBody = getTableBody(sortableTable); | ||
const tableHead = sortableTable.querySelector("thead"); | ||
@@ -324,2 +330,6 @@ const tableHeadHeaders = tableHead.querySelectorAll("th"); | ||
}); | ||
let isOnloadSort = th.classList.contains("onload-sort"); | ||
if (isOnloadSort) { | ||
th.click(); | ||
} | ||
} | ||
@@ -326,0 +336,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18223
315
63