• 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

5.88
/projects/igniteui-angular/src/lib/services/csv/csv-exporter.ts
1
import { EventEmitter, Injectable } from '@angular/core';
2
import { DEFAULT_OWNER, IExportRecord, IgxBaseExporter } from '../exporter-common/base-export-service';
3
import { ExportUtilities } from '../exporter-common/export-utilities';
4
import { CharSeparatedValueData } from './char-separated-value-data';
5
import { CsvFileTypes, IgxCsvExporterOptions } from './csv-exporter-options';
6
import { IBaseEventArgs } from '../../core/utils';
7

8
export interface ICsvExportEndedEventArgs extends IBaseEventArgs {
9
    csvData?: string;
10
}
11

12
/**
13
 * **Ignite UI for Angular CSV Exporter Service** -
14
 * [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/exporter-csv)
15
 *
16
 * The Ignite UI for Angular CSV Exporter service can export data in a Character Separated Values format from
17
 * both raw data (array) or from an `IgxGrid`.
18
 *
19
 * Example:
20
 * ```typescript
21
 * public localData = [
22
 *   { Name: "Eric Ridley", Age: "26" },
23
 *   { Name: "Alanis Brook", Age: "22" },
24
 *   { Name: "Jonathan Morris", Age: "23" }
25
 * ];
26
 *
27
 * constructor(private csvExportService: IgxCsvExporterService) {
28
 * }
29
 *
30
 * const opt: IgxCsvExporterOptions = new IgxCsvExporterOptions("FileName", CsvFileTypes.CSV);
31
 * this.csvExportService.exportData(this.localData, opt);
32
 * ```
33
 */
34
@Injectable({
35
    providedIn: 'root',
36
})
37
export class IgxCsvExporterService extends IgxBaseExporter {
2✔
38
    /**
39
     * This event is emitted when the export process finishes.
40
     * ```typescript
41
     * this.exporterService.exportEnded.subscribe((args: ICsvExportEndedEventArgs) => {
42
     * // put event handler code here
43
     * });
44
     * ```
45
     *
46
     * @memberof IgxCsvExporterService
47
     */
UNCOV
48
    public override exportEnded = new EventEmitter<ICsvExportEndedEventArgs>();
×
49

50
    private _stringData: string;
51

52
    protected exportDataImplementation(data: IExportRecord[], options: IgxCsvExporterOptions, done: () => void) {
UNCOV
53
        data = data.map((item) => item.data);
×
UNCOV
54
        const columnList = this._ownersMap.get(DEFAULT_OWNER);
×
55

UNCOV
56
        const csvData = new CharSeparatedValueData(data, options.valueDelimiter, columnList?.columns);
×
UNCOV
57
        csvData.prepareDataAsync((r) => {
×
UNCOV
58
            this._stringData = r;
×
UNCOV
59
            this.saveFile(options);
×
UNCOV
60
            this.exportEnded.emit({ csvData: this._stringData });
×
UNCOV
61
            done();
×
62
        });
63
    }
64

65
    private saveFile(options: IgxCsvExporterOptions) {
UNCOV
66
        switch (options.fileType) {
×
67
            case CsvFileTypes.CSV:
UNCOV
68
                this.exportFile(this._stringData, options.fileName, 'text/csv;charset=utf-8;');
×
UNCOV
69
                break;
×
70
            case CsvFileTypes.TSV:
71
            case CsvFileTypes.TAB:
UNCOV
72
                this.exportFile(this._stringData, options.fileName, 'text/tab-separated-values;charset=utf-8;');
×
UNCOV
73
                break;
×
74
        }
75
    }
76

77
    private exportFile(data: string, fileName: string, fileType: string): void {
UNCOV
78
        const blob = new Blob([data ? '\ufeff' : '', data], { type: fileType });
×
UNCOV
79
        ExportUtilities.saveBlobToFile(blob, fileName);
×
80
    }
81
}
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