使用angular 2导出ngx数据表中的PDF 2

使用angular 2导出ngx数据表中的PDF 2

问题描述:

我正在尝试导出ngxdatable在Angular 2中显示的pdf。怎么做?使用angular 2导出ngx数据表中的PDF 2

+0

NGX数据表不支持数据导出,和他们根据他们的文件,没有计划增加支持。 – Claies

居然还有一个办法......

  • 的问题是只有你过滤什么出口,所以事情是保持跟踪你的表的过滤DATAS的。

我一直在使用一个外部库,以便能够从文件我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>