With my very basic knowledge I have compiled the following function to save a html-table as .json file. This function works very well and quick as long as the html table is not filtered.
function invent2JSON(fname) {
var table = document.getElementById("myTable");
var header = [];
var rows = [];
var totalsObj = {rows};
for (var i = 0; i < table.rows[0].cells.length; i++) {
header.push(table.rows[0].cells[i].innerHTML);
}
for (var i = 1; i < table.rows.length; i++) {
var row = {};
for (var j = 0; j < table.rows[i].cells.length; j++) {
row[header[j]] = table.rows[i].cells[j].innerHTML;
}
rows.push(row);
}
var myBlobFile = new Blob([JSON.stringify(totalsObj,null,2)], { type: 'text/json;charset=utf-8' });
var url = window.URL || window.webkitURL;
var temp_link = document.createElement('a');
temp_link.download = fname+".json";
temp_link.href = URL.createObjectURL(myBlobFile);
//temp_link.hidden = true;
// This link should not be displayed
document.body.appendChild(temp_link);
temp_link.click();
document.body.removeChild(temp_link);
}
As soon as I apply the filter function ddtf.js (ddtf.js) to the html table and try to export the html table again as .json file I get an error message indicating that there is a Uncaught RangeError: Invalid string length. This error happens exactly at this line of the export function
var myBlobFile = new Blob([JSON.stringify(totalsObj,null,2)], { type: ‘text/json;charset=utf-8’ });
I really don’t get the point why I get this error message. Anyone around who has an idea? I thank you very much in advance.