table-sort-js
Advanced tools
Comparing version 1.1.5 to 1.1.6-b
{ | ||
"name": "table-sort-js", | ||
"version": "1.1.5", | ||
"version": "1.1.6b", | ||
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.", | ||
@@ -12,3 +12,2 @@ "license": "MIT", | ||
"sort", | ||
"table-sort-js", | ||
"sort-table-js", | ||
@@ -19,6 +18,5 @@ "table-sort", | ||
"HTML", | ||
"npm", | ||
"JavaScript", | ||
"js", | ||
"table sort", | ||
"tablesort", | ||
"table sort js", | ||
@@ -25,0 +23,0 @@ "js sort table", |
@@ -29,3 +29,3 @@ ![table-sort-js](https://img.shields.io/npm/v/table-sort-js) : https://www.npmjs.com/package/table-sort-js | ||
<td>John</td> | ||
<td>1977</td> | ||
<td>1977/12/4</td> | ||
<td>1</td> | ||
@@ -36,3 +36,3 @@ </tr> | ||
<td>Frank</td> | ||
<td>1976</td> | ||
<td>1976/10/27</td> | ||
<td>10</td> | ||
@@ -43,5 +43,18 @@ </tr> | ||
<td>Jason</td> | ||
<td>1978</td> | ||
<td>1978/4/6</td> | ||
<td>100</td> | ||
</tr> | ||
<tr> | ||
<td>Michael</td> | ||
<td>Jackson</td> | ||
<td>1958/8/29</td> | ||
<td>54</td> | ||
</tr> | ||
<tr> | ||
<td>Ben</td> | ||
<td>Tenison</td> | ||
<td>1994/7/21</td> | ||
<td>134</td> | ||
</tr> | ||
</tbody> | ||
@@ -58,1 +71,3 @@ </table> | ||
* Example of use: https://www.cssscript.com/minimal-table-sorter/ | ||
* Add `table-arrows` class to display aescending descending triangle |
@@ -12,3 +12,3 @@ /* | ||
Frontend: <script src="https://leewannacott.github.io/table-sort-js/table-sort.js"></script> or | ||
Download this file and Add <script src="table-sort.js"></script> to your HTML | ||
Download this file and add <script src="table-sort.js"></script> to your HTML | ||
@@ -26,3 +26,3 @@ Backend: npm install table-sort-js and use require("../node_modules/table-sort-js/table-sort.js") | ||
for (let sortableTable of document.getElementsByTagName("table")) { | ||
if (sortableTable.className === "table-sort") { | ||
if (sortableTable.classList.contains("table-sort")) { | ||
if (sortableTable.getElementsByTagName("thead").length === 0) { | ||
@@ -78,5 +78,6 @@ const the = document.createElement("thead"); | ||
} else { | ||
// Fill in blank table cells with a value(0) | ||
columnData.push("0#" + i); | ||
dictOfColumnIndexAndTableRow["0#" + i] = | ||
// Fill in blank table cells with the highest | ||
// value replacement character that works. | ||
columnData.push("ӿ#" + i); | ||
dictOfColumnIndexAndTableRow["ӿ#" + i] = | ||
tr.innerHTML; | ||
@@ -96,8 +97,26 @@ } | ||
// Sort naturally; default aescending unless th is using 'order-by-desc' as className. | ||
function clearArrows(arrowUp="▲",arrowDown="▼") { | ||
let ifDownArrow = th.innerText.includes(arrowDown); | ||
let ifUpArrow = th.innerText.includes(arrowUp); | ||
if ((ifDownArrow) === true || (ifUpArrow) === true) { | ||
th.innerText = th.innerText.replace(arrowUp,"") | ||
th.innerText = th.innerText.replace(arrowDown,"") | ||
} | ||
} | ||
let arrowUp=" ▲"; | ||
let arrowDown=" ▼"; | ||
// Sort naturally; default aescending unless th contains 'order-by-desc' as className. | ||
if (typeof columnData[0] !== "undefined") { | ||
originalColumnText = th.innerText | ||
if ( | ||
th.className === "order-by-desc" && | ||
th.classList.contains("order-by-desc") && | ||
timesClickedColumn === 1 | ||
) { | ||
if (sortableTable.classList.contains("table-arrows")){ | ||
clearArrows(arrowUp,arrowDown) | ||
th.insertAdjacentText("beforeend",arrowDown); | ||
} | ||
columnData.sort(naturalSortDescending, { | ||
@@ -107,6 +126,11 @@ numeric: true, | ||
}); | ||
} else if ( | ||
th.className === "order-by-desc" && | ||
th.classList.contains("order-by-desc") && | ||
timesClickedColumn === 2 | ||
) { | ||
if (sortableTable.classList.contains("table-arrows")){ | ||
clearArrows(arrowUp,arrowDown) | ||
th.insertAdjacentText("beforeend",arrowUp); | ||
} | ||
columnData.sort(naturalSortAescending, { | ||
@@ -117,5 +141,15 @@ numeric: true, | ||
timesClickedColumn = 0; | ||
} else if (timesClickedColumn === 1) { | ||
if (sortableTable.classList.contains("table-arrows")){ | ||
clearArrows(arrowUp,arrowDown) | ||
th.insertAdjacentText("beforeend",arrowUp); | ||
} | ||
columnData.sort(naturalSortAescending); | ||
} else if (timesClickedColumn === 2) { | ||
if (sortableTable.classList.contains("table-arrows")){ | ||
clearArrows(arrowUp,arrowDown) | ||
th.insertAdjacentText("beforeend",arrowDown); | ||
} | ||
columnData.sort(naturalSortDescending); | ||
@@ -127,2 +161,3 @@ timesClickedColumn = 0; | ||
getTableDataOnClick(); | ||
function returnSortedTable() { | ||
@@ -129,0 +164,0 @@ const tableRows = tableBody.querySelectorAll("tr"); |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13197
158
70
2
1