11/* eslint-disable max-len */
22import { AsyncPipe , CurrencyPipe } from '@angular/common' ;
33import { Component , ElementRef , EventEmitter , Input , OnInit , Output , ViewChild , DOCUMENT , inject } from '@angular/core' ;
4- import { CellType , GridSelectionMode , IGridKeydownEventArgs , IRowSelectionEventArgs , IgxCellEditorTemplateDirective , IgxCellTemplateDirective , IgxColumnComponent , IgxExcelTextDirective , IgxGridToolbarActionsComponent , IgxGridToolbarComponent , IgxGridToolbarExporterComponent , IgxGridToolbarHidingComponent , IgxGridToolbarPinningComponent } from 'igniteui-angular/grids/core' ;
4+ import { CellType , GridSelectionMode , IColumnExportingEventArgs , IGridKeydownEventArgs , IRowSelectionEventArgs , IgxCellEditorTemplateDirective , IgxCellTemplateDirective , IgxColumnComponent , IgxExcelTextDirective , IgxExporterEvent , IgxGridToolbarActionsComponent , IgxGridToolbarComponent , IgxGridToolbarExporterComponent , IgxGridToolbarHidingComponent , IgxGridToolbarPinningComponent , IgxPdfExporterOptions , IgxPdfExporterService , IgxPdfTextDirective } from 'igniteui-angular/grids/core' ;
55import { DefaultSortingStrategy , IgxOverlayOutletDirective , OverlaySettings , SortingDirection } from 'igniteui-angular/core' ;
66import { IgxGridComponent } from 'igniteui-angular/grids/grid' ;
77import { IgxSelectComponent , IgxSelectItemComponent } from 'igniteui-angular/select' ;
@@ -17,11 +17,12 @@ import { FormsModule } from '@angular/forms';
1717 selector : 'app-finjs-grid' ,
1818 templateUrl : './grid-finjs.component.html' ,
1919 styleUrls : [ './grid-finjs.component.scss' ] ,
20- imports : [ IgxGridComponent , IgxPreventDocumentScrollDirective , IgxGridToolbarComponent , IgxGridToolbarActionsComponent , IgxGridToolbarHidingComponent , IgxGridToolbarPinningComponent , IgxGridToolbarExporterComponent , IgxExcelTextDirective , IgxColumnComponent , IgxCellEditorTemplateDirective , IgxSelectComponent , FormsModule , IgxFocusDirective , IgxSelectItemComponent , IgxCellTemplateDirective , IgxIconComponent , IgxIconButtonDirective , IgxOverlayOutletDirective , AsyncPipe , CurrencyPipe ]
20+ imports : [ IgxGridComponent , IgxPreventDocumentScrollDirective , IgxGridToolbarComponent , IgxGridToolbarActionsComponent , IgxGridToolbarHidingComponent , IgxGridToolbarPinningComponent , IgxGridToolbarExporterComponent , IgxExcelTextDirective , IgxPdfTextDirective , IgxColumnComponent , IgxCellEditorTemplateDirective , IgxSelectComponent , FormsModule , IgxFocusDirective , IgxSelectItemComponent , IgxCellTemplateDirective , IgxIconComponent , IgxIconButtonDirective , IgxOverlayOutletDirective , AsyncPipe , CurrencyPipe ]
2121} )
2222export class GridFinJSComponent implements OnInit {
2323 private el = inject ( ElementRef ) ;
2424 private document = inject < Document > ( DOCUMENT ) ;
25+ private pdfExportService = inject ( IgxPdfExporterService ) ;
2526 dataService = inject ( SignalRService ) ;
2627
2728 @ViewChild ( 'grid1' , { static : true } ) public grid : IgxGridComponent ;
@@ -116,6 +117,34 @@ export class GridFinJSComponent implements OnInit {
116117 this . chartColumnKeyDown . emit ( target . row . data ) ;
117118 }
118119
120+ public exportStarted ( args : IgxExporterEvent ) {
121+ ( args . options as IgxPdfExporterOptions ) . pageSize = "A3" ;
122+
123+ const includedFields = new Set ( [
124+ 'id' ,
125+ 'category' ,
126+ 'type' ,
127+ 'contract' ,
128+ 'settlement' ,
129+ 'country' ,
130+ 'region' ,
131+ 'lastupdated' ,
132+ 'openprice' ,
133+ 'price' ,
134+ 'change' ,
135+ 'buy' ,
136+ 'sell'
137+ ] ) ;
138+
139+ this . pdfExportService . columnExporting . subscribe ( ( exportArgs : IColumnExportingEventArgs ) => {
140+ const field = exportArgs . field . toLowerCase ( ) ;
141+ if ( ! includedFields . has ( field ) ) {
142+ exportArgs . cancel = true ;
143+ }
144+ } ) ;
145+
146+ }
147+
119148 get gridWrapper ( ) : HTMLElement {
120149 return this . el . nativeElement . querySelector ( '.grid__wrapper' ) as HTMLElement ;
121150 }
0 commit comments