2017-08-30 112 views

回答

1

居然還有一個辦法......

  • 的問題是隻有你過濾什麼出口,所以事情是保持跟蹤你的表的過濾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>