Skip to content

Commit 75d0b67

Browse files
Merge pull request #14742 from IgniteUI/rivanova/fix-14737-17.2.x
fix(excel-export): exportData when columnExporting is canceled - 17.2.x
2 parents d92ce79 + 304b930 commit 75d0b67

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

projects/igniteui-angular/src/lib/services/excel/excel-exporter.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ExportUtilities } from '../exporter-common/export-utilities';
22
import { IgxExcelExporterService } from './excel-exporter';
33
import { IgxExcelExporterOptions } from './excel-exporter-options';
4+
import { IColumnExportingEventArgs } from '../exporter-common/base-export-service';
45
import { ZipWrapper } from './zip-verification-wrapper.spec';
56
import { FileContentData } from './test-data.service.spec';
67
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
@@ -117,6 +118,22 @@ describe('Excel Exporter', () => {
117118
}
118119
});
119120

121+
it('should export data successfully when \'columnExporting\' is canceled.', async () => {
122+
options.columnWidth = 50;
123+
124+
exporter.columnExporting.subscribe((args: IColumnExportingEventArgs) => {
125+
if (args.field === 'phone') {
126+
args.cancel = true;
127+
}
128+
});
129+
130+
const wrapper = await getExportedData(SampleTestData.contactsData(), options);
131+
132+
wrapper.verifyStructure();
133+
await wrapper.verifyTemplateFilesContent();
134+
await wrapper.verifyDataFilesContent(actualData.contactsDataSkippedColumnContent);
135+
});
136+
120137
const getExportedData = (data: any[], exportOptions: IgxExcelExporterOptions) => {
121138
const result = new Promise<ZipWrapper>((resolve) => {
122139
exporter.exportEnded.pipe(first()).subscribe((value) => {

projects/igniteui-angular/src/lib/services/excel/test-data.service.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,26 @@ export class FileContentData {
435435
return this.createData();
436436
}
437437

438+
public get contactsDataSkippedColumnContent() {
439+
this._sharedStringsData = `count="6" uniqueCount="6"><si><t>name</t></si><si><t>Terrance Orta</t></si>` +
440+
`<si><t>Richard Mahoney LongerName</t></si><si><t>Donna Price</t></si><si><t></t></si>` +
441+
`<si><t>Dorothy H. Spencer</t></si>`;
442+
443+
this._tableData = `ref="A1:A6" totalsRowShown="0">
444+
<autoFilter ref="A1:A6"/><tableColumns count="1"><tableColumn id="1" name="name"/></tableColumns>`;
445+
446+
this._worksheetData =
447+
`<dimension ref="A1:A6"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"></sheetView></sheetViews>` +
448+
`<sheetFormatPr defaultRowHeight="15" x14ac:dyDescent="0.25"/><cols><col min="1" max="1" width="50" customWidth` +
449+
`="1"/></cols><sheetData><row r="1"><c r="A1" t="s"><v>0</v>` +
450+
`</c></row><row r="2"><c r="A2" t="s"><v>1</v></c></row><row r="3">` +
451+
`<c r="A3" t="s"><v>2</v></c></row><row r="4"><c r="A4" t="s"><v>3</v></c>` +
452+
`</row><row r="5"><c r="A5" t="s"><v>4</v></c></row><row r="6"><c r="A6" t="s"><v>5</v></c>` +
453+
`</row></sheetData>`;
454+
455+
return this.createData();
456+
}
457+
438458
public get noHeadersStringDataContent() {
439459
this._sharedStringsData = `count="6" uniqueCount="6"><si><t>Column1</t></si><si><t>Terrance Orta</t></si>` +
440460
`<si><t>Richard Mahoney LongerName</t></si><si><t>Donna Price</t></si><si><t>Lisa Landers</t></si><si><t>` +

projects/igniteui-angular/src/lib/services/exporter-common/base-export-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export abstract class IgxBaseExporter {
424424
});
425425
}
426426

427-
const targetCol = mapRecord.columns.filter(c => column.columnGroupParent !== null && c.columnGroup === column.columnGroupParent)[0];
427+
const targetCol = mapRecord.columns.filter(c => column.columnGroupParent !== null && column.columnGroupParent !== undefined && c.columnGroup === column.columnGroupParent)[0];
428428
if (targetCol !== undefined) {
429429
targetCol.columnSpan -= span;
430430

0 commit comments

Comments
 (0)