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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

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

3.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
    imports: [IgxButtonDirective, IgxRippleDirective, IgxIconComponent, NgIf, IgxToggleDirective, IgxExcelTextDirective, IgxCSVTextDirective]
55
})
56
export class IgxGridToolbarExporterComponent extends BaseToolbarDirective {
2✔
57

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

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

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

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

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

89
    /**
90
     * Indicates whether there is an export in progress.
91
     */
UNCOV
92
    protected isExporting = false;
×
93

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

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

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

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

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

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

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

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

143
        exporter.export(this.grid, options);
×
144
    }
145
}
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