No heading Javascript JSON Array -> CSV Export -


hi guys export works dont have heading :/

i dont know problem information: i'm getting data database it's json array

can me?

my code:

        var csvcontent = "data:text/csv;charset=utf-8,";         $("#csv").click(function(){         // iterating through objects          data.foreach(function (infoarray, index) {           // fetching keys of single object          var _keys = object.keys(infoarray);          var datastring = [];  //test heading        //  var heading = ["timestamp ; toolversion ; monitortype ; serialnumber; monitorrevision ; testscript ; testcase ;testcaseversion ;testscope; duration; result; clickcount ;morbalwaitaverage; morbalwaitmin ; morbalwaitmax ; timingproblems ; abortedretries ; operationretries ; acknowledgeaverage ; increasedupdatetime ; falsescrolls "];         //datastring.push(heading);          if(index==0){          [].foreach.call(_keys, function(inst, i){             datastring.push(inst);          });          datastring = datastring.join(";");          csvcontent += index < data[0].length ? datastring + "\n" : datastring;          datastring = [];         } else{          [].foreach.call(_keys, function(inst, i){             datastring.push(infoarray[inst]);          });             datastring = datastring.join(";");           csvcontent += index < data.length ? datastring + "\n" : datastring;           }         });           var encodeduri = encodeuri(csvcontent);         var link = document.createelement("a");         link.setattribute("href", encodeduri);         link.setattribute("download", "my_data.csv");         link.click();           }); 

this works:

    //--------------------------- csv export --------------------------------      var csvcontent = "data:text/csv;charset=utf-16,";     $("#csv").click(function()     {         var _keys = object.keys(data[0]);         datastring = "_"+_keys.join(";");         csvcontent += datastring + "\n";         // iterating through objects         data.foreach(function (infoarray, index) {              var datastring = [];              [].foreach.call(_keys, function(inst, i){                 datastring.push(infoarray[inst]);              });               datastring = datastring.join(";");               csvcontent += index < data.length ? datastring + "\n" : datastring;     });       var encodeduri = encodeuri(csvcontent);     var link = document.createelement("a");     link.setattribute("href", encodeduri);     link.setattribute("download", "my_data.csv");     link.click();       }); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -