javascript - Export to csv using java script -


i facing problem exporting csv.

problems:

1) have export html table csv file . can change delimiter of csv file else semicolon. if have values in table under same column separated comma, in csv sheet showing in different column.

2) code not working ie , working mozilla

3) wanted user save csv file. getting automatically saved. please find code . can body of issue.

    function exporttabletocsv(filename) {          var tab = $('#searchobjecttabletabs').tabs('getselected');// selecting table         var tabindex = $('#searchobjecttabletabs').tabs('gettabindex', tab);         var data;         var rows;           if (tabindex == '0') // first index of tab under table displayed         {             data = $('#dg');//only 1 table             rows = $('#dg').datagrid('getrows');           } else if (tabindex == '1') // second index         {             data = $('#doc').first(); //only 1 table             rows = $('#doc').datagrid('getrows');          }           var csvdata = [];         var tmparr = [];         var tmpstr = '';         data.find("tr").each(function ()          {             if ($(this).find("th").length) {                 $(this).find("th").each(function () {                     tmpstr = $(this).text().replace(/"/g, '""');                     tmparr.push('"' + tmpstr + '"');                 });                                    csvdata.push(tmparr);             }             tmparr = [];             $.each(exportarray, function (index, value)              {              csvdata.push(exportarray[index].type + "," + exportarray[index].status + "," + exportarray[index].id + "," + exportarray[index].itemrev + "," + exportarray[index].desc + "," + exportarray[index].owner + "," + exportarray[index].ogrp);              });             csvdata.push(tmparr.join('\n'));              // printobject(tmparr);         });         alert('before this');             var output = csvdata.join('\n');          csvdata = 'data:application/csv;charset=utf-8,' + encodeuricomponent(output);      $(this)         .attr({         'download': filename,             'href': csvdata,             'target': '_blank'             'delimiter':';'     });      alert('done'); }   $(".export").on('click', function (event) {     // csv     exporttabletocsv.apply(this,['export.csv']);     }); 


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -