Displaying CSV headers using PapaParse plugin

I am using PapaParse plugin for csv files. I have this function below that creates a table to display CSV results.

function handleFileSelect(evt) {
var file = evt.target.files[0];

Papa.parse(file, {
  header: true,
  dynamicTyping: true,
  complete: function(results) {

    $.each(results.data, function(i, el) {
        var row = $("<tr/>");
        row.append($("<td/>").text(i));
        $.each(el, function(j, cell) {
                row.append($("<td/>").text(cell));
        });
        $("#results tbody").append(row);
    });


  }
  });

}

      

Even with installation, header:true

I can't get the headers to show up in the table, but everything else is showing fine.

And to be honest, I found this script online and I am having trouble understanding how it works.

Any ideas? Thank you in advance!

+3


source to share


1 answer


Ok I figured it out ...

The title headers were contained in another object. results.meta['fields']



This is how I print the papa analysis results.

$.each(results.meta['fields'], function(i) {
    $("#headers").append($("<td/>").text(results.meta['fields'][i]));
});

      

+2


source







All Articles