如何通过JSON将数据传递给jsPDF autotable

时间:2017-09-12 07:01:23

标签: angular jspdf-autotable

download() {
    var columns = [
        { title: "Producto", dataKey: "producto" },
        { title: "Fecha", dataKey: "fecha" }
    ];
    var data = [{ "producto": "ddf", "fecha": "cwx" }];
    var doc = new jsPDF('p', 'pt');
    console.log("1", data);
    console.log("2", columns);
    doc.autoTable(columns, data);
    doc.save('table.pdf');            
    //console.log("3", data);
    //this.PdfServiceService.getAll().subscribe(c => {
    //    console.log("4", this.country = c.pdfdata)
    //    this.data = this.country;
    //});  
};

<button (click)="download()">Generate PDF</button>

我想通过JSON数据传递数据(var data)。我无法将数据传递到doc auto表中。这是我尝试过的链接:https://www.npmjs.com/package/jspdf-autotable

1 个答案:

答案 0 :(得分:0)

只需在数据中添加值并使用数组[ [],[]]的数组,它将起作用。

var columns = ['id', 'Department', 'Joiners', 'Resignations', 'Terminations']

var data= [[1, 'IT',2, 1,0],[2, 'Comp', 1, 0, 0]]