3

In this only one CSV file would open. I want to open multiple CSV files and edit them in an HTML table. Please help.

$(function() {
    Papa.parse("abc.csv", {
        download: true,
        complete: function(results) {
            console.log("Remote file parsed!", results.data);
            $.each(results.data, function(i, el) {
                var row = $("<tr/>");
                row.append($("<td/>").text(i));
                $.each(el, function(j, cell) {
                    if (cell !== "")
                        row.append($("<td/>").text(cell));
                });
                $("#results tbody").append(row);
            });
        }
    });
});     
Jørgen R
  • 10,568
  • 7
  • 42
  • 59
Ghost
  • 213
  • 1
  • 2
  • 10

1 Answers1

0

You have to do a loop, here we have an array of your csv files :

var csv_array = ["abc.csv","def.csv","ghi.csv"];
    $(function() {
        $(csv_array).each(function(){
            Papa.parse(this.toString(), {
                download: true,
                complete: function(results) {
                    console.log("Remote file parsed!", results.data);
                    $.each(results.data, function(i, el) {
                        var row = $("<tr/>");
                        row.append($("<td/>").text(i));
                        $.each(el, function(j, cell) {
                            if (cell !== "")
                                row.append($("<td/>").text(cell));
                        });
                        $("#results tbody").append(row);
                    });
                }
            });

        })

    }); 
tomtomtom
  • 829
  • 1
  • 8
  • 20
  • but it is at edit click.. at every diffrent edit a different csv will be open so how to fetch them from different clicks – Ghost Feb 04 '15 at 09:22
  • try to use `$("#results tbody").empty();` just after `$(function() {`, if I understand well – tomtomtom Feb 04 '15 at 09:29
  • and what about editor.. this page will open in html table but i can't edit . can you help to edit table – Ghost Feb 04 '15 at 09:32