翻譯|行業資訊|編輯:龔雪|2022-12-01 10:46:30.963|閱讀 178 次
概述:本文主要介紹DevExtreme控件的DataGrid & TreeList組件的新功能,歡迎下載最新版控件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
DevExtreme擁有高性能的HTML5 / JavaScript小部件集合,使您可以利用現代Web開發堆棧(包括React,Angular,ASP.NET Core,jQuery,Knockout等)構建交互式的Web應用程序,該套件附帶功能齊全的數據網格、交互式圖表小部件、數據編輯器等。
DevExpress技術交流群6:600715373 歡迎一起進群討論
要啟用Data Grid的PDF導出選項,請導入庫。在組件中,設置export.屬性為true然后指定導出格式。接下來的操作顯示DataGrid中的Export按鈕,單擊此按鈕時,將觸發函數(其中開發者應該調用pdfExporter.方法)。
<dx-data-grid ... (onExporting)="onExporting($event)" > <dxo-export [enabled]="true" [formats]="['pdf']" ></dxo-export> </dx-data-grid>
import { Component } from '@angular/core'; import { exportDataGrid } from 'devextreme/pdf_exporter'; import { jsPDF } from 'jspdf'; // ... export class AppComponent { onExporting(e) { const doc = new jsPDF(); exportDataGrid({ jsPDFDocument: doc, component: e.component, }).then(() => { doc.save('DataGrid.pdf'); }); } }
單元格自定義
開發人員可以自定義單元格內容并在PDF文檔中繪制自定義單元格。
函數允許開發者為導出的PDF文檔自定義單個DataGrid單元格的外觀(例如,可以更改單元格使用的字體樣式)。
onExporting(e) { const doc = new jsPDF(); exportDataGrid({ jsPDFDocument: doc, component: e.component, customizeCell({ gridCell, pdfCell }) { //... } }).then(() => { doc.save('DataGrid.pdf'); }); }
如果希望在繪制單元格時覆蓋默認繪制邏輯并應用自己的繪制邏輯,請使用函數。在下面的例子中,這個函數在PDF文檔中為" Website "列繪制并自定義一個單元格:
onExporting(e) { const doc = new jsPDF(); exportDataGrid({ jsPDFDocument: doc, component: e.component, customDrawCell({ gridCell, pdfCell }) { //... } }).then(() => { doc.save('DataGrid.pdf'); }); }
頁眉和頁腳
開發人員可以輕松地向導出的DataGrid添加頁眉和頁腳。
DataGrid組件位于PdfExportDataGridProps中指定點的PdfExportDataGridProps. 屬性的頁眉之前。
對于頁腳位置,使用函數,這個函數允許開發者計算組件最右邊單元格的坐標。
導出圖片
庫API還允許將自定義內容導出為PDF(如圖像),對于圖像導出,可以調用方法,然后處理事件為導出的DataGrid定制行。
onExporting(e) { const doc = new jsPDF(); exportDataGrid({ jsPDFDocument: doc, component: e.component, onRowExporting: (e) => { // Customize rows }, customDrawCell: (e) => { // Detect picture cell doc.addImage(e.gridCell.value, 'PNG', e.rect.x, e.rect.y, e.rect.w, e.rect.h); e.cancel = true; } }).then(() => { doc.save('DataGrid.pdf'); }); }
導出多個網格
要將多個DataGrid組件導出到一個文件中,并在PDF文檔的不同頁面上排列它們,請在Promises鏈中使用pdfExporter.方法。
exportGrids() { const doc = new jsPDF(); DevExpress.pdfExporter.exportDataGrid({ jsPDFDocument: doc, component: gridOneInstance, }).then(() => { doc.addPage(); DevExpress.pdfExporter.exportDataGrid({ jsPDFDocument: doc, component: gridTwoInstance, }).then(() => { doc.save('MultipleGrids.pdf'); }); }); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網