Reputation: 519
I'm using this code to export tables off of a web page.
This snippet of code works fine when I export tables of < 1000 rows or so, but when I try to export larger tables I get the error: Failed Network Error. This happens in chrome. It doesn't do anything in IE (surprise).
Is it a memory issue? Any ideas how I can export large tables without running into issues?
Thanks for any help
var dt = new Date();
var day = dt.getDate();
var month = dt.getMonth() + 1;
var year = dt.getFullYear();
var hour = dt.getHours();
var mins = dt.getMinutes();
var postfix = month + "." + day + "." + year + "_" + hour + "." + mins;
//creating a temporary HTML link element (they support setting file names)
var a = document.createElement('a');
//getting data from our div that contains the HTML table
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById('datatable');
var table_html = table_div.outerHTML.replace(/ /g, '%20');
a.href = data_type + ', ' + table_html;
//setting the file name
a.download = 'MachineReport_' + postfix + '.xls';
//triggering the function
a.click();
//just in case, prevent default behaviour
e.preventDefault();
Upvotes: 1
Views: 4132
Reputation: 21
I had faced the same problem. This help me solved it. Please try replace:
a.href = data_type + ', ' + table_html;
With:
xData = new Blob([table_html], { type: 'text/csv' });
var xUrl = URL.createObjectURL(xData);
a.href = xUrl;
Upvotes: 2
Reputation: 519
No answers, but after research it seems to be part of the 2meg limit Chrome imposes when trying to execute this script. I do not know of a work around.
Upvotes: 0