简体   繁体   中英

Export to html table csv not working in IE

I have a html table with 16000 rows 5 columns. I am using the below script to export the table to csv but when the No. of rows are huge the screen goes blank and the export doesn't happen.

var ifrm =  document.createElement('iframe');
ifrm.id = "txtExport";
ifrm.style.display = 'none';
document.appendChild(ifrm);  
txtExport.document.open("txt/html","replace");
txtExport.document.write('sep=,\r\n' +csvData);
txtExport.document.close();
txtExport.focus(); 
txtExport.document.execCommand("SaveAs",true,"Export.csv")
ifrm.parentNode.removeChild(ifrm); 

Can someone help me with this or suggest a workaround.

Your code might only work for, IE and not for other browsers, please correct me if I am wrong, but for the functionality you are asking, you can actually use datatables for that.

The code is pretty simple:

<script>
  $(document) .ready(function(){
      $('#myTable').DataTable({
        dom: 'Bfrtip',
        buttons: [
          'csv', 'pdf', 'print'
        ]
      });
  });      
<script>

FYI: I have created the jsfiddle as well,although it needs more references to other files, please look in to that once, on the left hand side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM