• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 15140530896

20 May 2025 02:39PM CUT coverage: 91.597%. Remained the same
15140530896

Pull #15000

github

web-flow
Merge a4f1b34ad into 310d1baa8
Pull Request #15000: fix(grid): add coerceToInt attribute to IPinningConfig and pagingMode props - 18.2.x

13004 of 15241 branches covered (85.32%)

26347 of 28764 relevant lines covered (91.6%)

34026.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/projects/igniteui-angular/src/lib/grids/toolbar/grid-toolbar-exporter.component.ts
1
import { Component, Input, Output, EventEmitter, Inject, booleanAttribute } from '@angular/core';
2
import { first } from 'rxjs/operators';
3
import { BaseToolbarDirective } from './grid-toolbar.base';
4
import { IgxExcelTextDirective, IgxCSVTextDirective } from './common';
5
import {
6
    CsvFileTypes,
7
    IgxBaseExporter,
8
    IgxCsvExporterOptions,
9
    IgxCsvExporterService,
10
    IgxExcelExporterOptions,
11
    IgxExcelExporterService
12
} from '../../services/public_api';
13
import { IgxToggleDirective } from '../../directives/toggle/toggle.directive';
14
import { GridType } from '../common/grid.interface';
15
import { IgxToolbarToken } from './token';
16
import { NgIf } from '@angular/common';
17
import { IgxIconComponent } from '../../icon/icon.component';
18
import { IgxRippleDirective } from '../../directives/ripple/ripple.directive';
19
import { IgxButtonDirective } from '../../directives/button/button.directive';
20

21

22
export type IgxExporterOptions = IgxCsvExporterOptions | IgxExcelExporterOptions;
23

24
/* jsonAPIComplexObject */
25
/* wcAlternateName: ExporterEventArgs */
26
export interface IgxExporterEvent {
27
    exporter: IgxBaseExporter;
28
    /* alternateType: ExporterOptionsBase */
29
    options: IgxExporterOptions;
30
    grid: GridType;
31
    cancel: boolean;
32
}
33

34

35
/* blazorElement */
36
/* wcElementTag: igc-grid-toolbar-exporter */
37
/* blazorIndirectRender */
38
/* jsonAPIManageItemInMarkup */
39
/* singleInstanceIdentifier */
40
/**
41
 * Provides a pre-configured exporter component for the grid.
42
 *
43
 * @remarks
44
 * This component still needs the actual exporter service(s) provided in the DI chain
45
 * in order to export something.
46
 *
47
 * @igxModule IgxGridToolbarModule
48
 * @igxParent IgxGridToolbarComponent
49
 *
50
 */
51
@Component({
52
    selector: 'igx-grid-toolbar-exporter',
53
    templateUrl: './grid-toolbar-exporter.component.html',
54
    standalone: true,
55
    imports: [IgxButtonDirective, IgxRippleDirective, IgxIconComponent, NgIf, IgxToggleDirective, IgxExcelTextDirective, IgxCSVTextDirective]
56
})
57
export class IgxGridToolbarExporterComponent extends BaseToolbarDirective {
2✔
58

59
    /**
60
     * Show entry for CSV export.
61
     */
62
    @Input({ transform: booleanAttribute })
63
    public exportCSV = true;
7✔
64

65
    /**
66
     * Show entry for Excel export.
67
     */
68
    @Input({ transform: booleanAttribute })
69
    public exportExcel = true;
7✔
70

71
    /**
72
     * The name for the exported file.
73
     */
74
    @Input()
75
    public filename = 'ExportedData';
7✔
76

77
    /**
78
     * Emitted when starting an export operation. Re-emitted additionally
79
     * by the grid itself.
80
     */
81
    @Output()
82
    public exportStarted = new EventEmitter<IgxExporterEvent>();
7✔
83

84
    /**
85
     * Emitted on successful ending of an export operation.
86
     */
87
    @Output()
88
    public exportEnded = new EventEmitter<void>();
7✔
89

90
    /**
91
     * Indicates whether there is an export in progress.
92
     */
93
    protected isExporting = false;
7✔
94

95
    constructor(
96
        @Inject(IgxToolbarToken) toolbar: IgxToolbarToken,
97
        private excelExporter: IgxExcelExporterService,
7✔
98
        private csvExporter: IgxCsvExporterService,
7✔
99
    ) {
100
        super(toolbar);
7✔
101
    }
102

103
    protected exportClicked(type: 'excel' | 'csv', toggleRef?: IgxToggleDirective) {
104
        toggleRef?.close();
×
105
        this.export(type);
×
106
    }
107

108
    /* alternateName: exportGrid */
109
    /**
110
     * Export the grid's data
111
     * @param type File type to export
112
     */
113
    public export(type: 'excel' | 'csv'): void {
114
        let options: IgxExporterOptions;
115
        let exporter: IgxBaseExporter;
116

117
        switch (type) {
×
118
            case 'csv':
119
                options = new IgxCsvExporterOptions(this.filename, CsvFileTypes.CSV);
×
120
                exporter = this.csvExporter;
×
121
                break;
×
122
            case 'excel':
123
                options = new IgxExcelExporterOptions(this.filename);
×
124
                exporter = this.excelExporter;
×
125
        }
126

127
        const args = { exporter, options, grid: this.grid, cancel: false } as IgxExporterEvent;
×
128

129
        this.exportStarted.emit(args);
×
130
        this.grid.toolbarExporting.emit(args);
×
131
        this.isExporting = true;
×
132
        this.toolbar.showProgress = true;
×
133

134
        if (args.cancel) {
×
135
            return;
×
136
        }
137

138
        exporter.exportEnded.pipe(first()).subscribe(() => {
×
139
            this.exportEnded.emit();
×
140
            this.isExporting = false;
×
141
            this.toolbar.showProgress = false;
×
142
        });
143

144
        exporter.export(this.grid, options);
×
145
    }
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc