我正在尝试导出 ngxdatable 在 Angular 2 中显示的 pdf。怎么做?
问问题
5579 次
1 回答
3
其实有办法...
- 问题是只导出您过滤的内容,所以问题是跟踪表的过滤数据。
我一直在使用外部库来从我的 Angular4 应用程序中导出文档:https ://github.com/eligrey/FileSaver.js/
这是我用来提取数据的示例代码。我将此方法绑定到一个按钮以触发事件:
打字稿组件:
// Notice the parameters from the service call that give me back my filtered datas
exportDatas(documentType: string) {
this.equipmentService.getExportDatas(this.detail.equipment.id, this.beginDate, this.endDate, this.frameType, documentType, this.timezoneOffset, this.translateService.currentLang)
.subscribe(result => {
const blob = new Blob([result.blob()]);
const objectUrl = URL.createObjectURL(blob);
FileSaver.saveAs(blob, 'Export.' + documentType);
});
}
模板面:
<div fxLayoutAlign="end">
<span class="label">{{'EQP_HISTORY.EXPORT'|translate}} :</span>
<button (click)="exportDatas('csv')" type="button">CSV</button>
<button (click)="exportDatas('pdf')" type="button">PDF</button>
</div>
于 2017-08-30T15:42:29.970 回答