simple-datatables
Advanced tools
Comparing version
{ | ||
"name": "simple-datatables", | ||
"version": "7.0.1", | ||
"version": "7.0.2", | ||
"description": "A lightweight, dependency-free JavaScript HTML table plugin.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -16,3 +16,3 @@ import {stringToObj} from "diff-dom" | ||
if (!(typeof cell === "string")) { | ||
cellData.text = String(cell) | ||
cellData.text = String(cellData.data) | ||
cellData.order = cellData.text | ||
@@ -23,14 +23,14 @@ } | ||
if (columnSettings.format) { | ||
cellData.order = parseDate(String(cell), columnSettings.format) | ||
cellData.order = parseDate(String(cellData.data), columnSettings.format) | ||
} | ||
break | ||
case "number": | ||
cellData.text = String(cell as number) | ||
cellData.data = parseInt(cell as string, 10) | ||
cellData.text = String(cellData.data as number) | ||
cellData.data = parseInt(cellData.data as string, 10) | ||
break | ||
case "html": { | ||
const node = Array.isArray(cell) ? | ||
const node = Array.isArray(cellData.data) ? | ||
{nodeName: "TD", | ||
childNodes: (cell as nodeType[])} : // If it is an array, we assume it is an array of nodeType | ||
stringToObj(`<td>${String(cell)}</td>`) | ||
childNodes: (cellData.data as nodeType[])} : // If it is an array, we assume it is an array of nodeType | ||
stringToObj(`<td>${String(cellData.data)}</td>`) | ||
cellData.data = node.childNodes || [] | ||
@@ -43,6 +43,6 @@ const text = objToText(node) | ||
case "boolean": | ||
if (typeof cell === "string") { | ||
cell = cell.toLowerCase().trim() | ||
if (typeof cellData.data === "string") { | ||
cellData.data = cellData.data.toLowerCase().trim() | ||
} | ||
cellData.data = !["false", false, null, undefined, 0].includes(cell as (string | number | boolean | null | undefined)) | ||
cellData.data = !["false", false, null, undefined, 0].includes(cellData.data as (string | number | boolean | null | undefined)) | ||
cellData.order = cellData.data ? 1 : 0 | ||
@@ -56,3 +56,3 @@ cellData.text = String(cellData.data) | ||
default: | ||
cellData.text = JSON.stringify(cell) | ||
cellData.text = JSON.stringify(cellData.data) | ||
break | ||
@@ -92,2 +92,8 @@ } | ||
export const readTableData = (dataOption: DataOption, dom: (HTMLTableElement | undefined)=undefined, columnSettings, defaultType, defaultFormat) => { | ||
const decodeDOM = document.createElement("textarea") | ||
const decode = function(input: string) { | ||
decodeDOM.innerHTML = input | ||
return decodeDOM.value | ||
} | ||
const data = { | ||
@@ -101,3 +107,3 @@ data: [], | ||
data.headings = Array.from(dom.tHead.querySelectorAll("th")).map((th, index) => { | ||
const heading = readHeaderCell(th.innerHTML) | ||
const heading = readHeaderCell(decode(th.innerHTML)) | ||
if (!columnSettings[index]) { | ||
@@ -150,3 +156,3 @@ columnSettings[index] = { | ||
row => Array.from(row.cells).map( | ||
(cell, index) => readDataCell(cell.dataset.content || cell.innerHTML, columnSettings[index]) | ||
(cell, index) => readDataCell(cell.dataset.content || decode(cell.innerHTML), columnSettings[index]) | ||
) | ||
@@ -153,0 +159,0 @@ ) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
3557955
0.14%14837
0.11%