Export Selected Grid Rows to PDF
Environment
Product | Progress® Kendo UI for Angular Grid |
Description
How can I export only the selected rows of the Kendo UI for Angular Grid to PDF?
Solution
By default, the PDF generates a file of what is currently visible on the page. To export only the selected Grid rows to PDF:
-
Create a second Grid off-screen and bind its data to the selected rows of the visible Grid.
<div style="position: absolute; top: 0; left: -10000px; width: 500px;"> <kendo-grid [kendoGridBinding]="mySelection" #pdfGrid> ... </kendo-grid> </div>
-
To store the whole
dataItem
in theselectedKeys
collection, provide a custom callback to thekendoGridSelectBy
directive of the visible Grid.<kendo-grid ... [kendoGridSelectBy]="selectBy" [(selectedKeys)]="mySelection" ></kendo-grid>
public selectBy = (args: RowArgs) => { return args.dataItem; };
-
Inside the click handler, export the hidden Grid data to PDF by using the
saveAsPDF
method of the component.@ViewChild('pdfGrid') public hiddenGrid: GridComponent; public onExport() { this.hiddenGrid.saveAsPDF(); }
The following example demonstrates the full implementation of the suggested approach.