在 primeng 数据表中导出 pdf 在 Angular 9 中不起作用
Export pdf in primeng datatable is not working in Angular 9
我尝试在 Angular9 的 Primeng 数据表中实现导出为 PDF。我的代码如下:
exportPdf() {
this.cols = [
{ field: 'code', header: 'Code' },
{ field: 'name', header: 'Name' },
{ field: 'category', header: 'Category' },
{ field: 'quantity', header: 'Quantity' }
];
this.exportColumns = this.cols.map(col => ({title: col.header, dataKey: col.field})); console.log(this.exportColumns)
import("jspdf").then(jsPDF => {
import("jspdf-autotable").then(x => {
const doc = new jsPDF.default(0,0);
doc.autoTable(this.exportColumns, this.products);
doc.save('products.pdf');
})
})
}
但是我收到这个错误:
error TS2345: Argument of type '0' is not assignable to parameter of type 'string'.
in const doc = new jsPDF.default(0,0);
我还安装了这些:
"jspdf": "^1.5.3",
"jspdf-autotable": "^3.5.13"
我该如何解决这个错误。有人可以帮我吗?
默认方法将第一个参数作为字符串 '"p" | "portrait" | "l" | "landscape"'
,第二个参数是单位并采用这些值 "pt" | "px" | "in" | "mm" | "cm" | "ex" | "em" | "pc"
import jsPDF from "jspdf";
import "jspdf-autotable";
...
exportPdf() {
const doc = new jsPDF('p','pt'); // or like this new jsPDF();
doc.autoTable(this.exportColumns, this.products);
doc.save("products.pdf");
}
我尝试在 Angular9 的 Primeng 数据表中实现导出为 PDF。我的代码如下:
exportPdf() {
this.cols = [
{ field: 'code', header: 'Code' },
{ field: 'name', header: 'Name' },
{ field: 'category', header: 'Category' },
{ field: 'quantity', header: 'Quantity' }
];
this.exportColumns = this.cols.map(col => ({title: col.header, dataKey: col.field})); console.log(this.exportColumns)
import("jspdf").then(jsPDF => {
import("jspdf-autotable").then(x => {
const doc = new jsPDF.default(0,0);
doc.autoTable(this.exportColumns, this.products);
doc.save('products.pdf');
})
})
}
但是我收到这个错误:
error TS2345: Argument of type '0' is not assignable to parameter of type 'string'.
in const doc = new jsPDF.default(0,0);
我还安装了这些:
"jspdf": "^1.5.3",
"jspdf-autotable": "^3.5.13"
我该如何解决这个错误。有人可以帮我吗?
默认方法将第一个参数作为字符串 '"p" | "portrait" | "l" | "landscape"'
,第二个参数是单位并采用这些值 "pt" | "px" | "in" | "mm" | "cm" | "ex" | "em" | "pc"
import jsPDF from "jspdf";
import "jspdf-autotable";
...
exportPdf() {
const doc = new jsPDF('p','pt'); // or like this new jsPDF();
doc.autoTable(this.exportColumns, this.products);
doc.save("products.pdf");
}