Skip to content

Commit 2581dc3

Browse files
committed
fix(CSV): Skip group columns when exporting to CSV.
1 parent af43574 commit 2581dc3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

projects/igniteui-angular/src/lib/services/csv/char-separated-value-data.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ExportUtilities } from '../exporter-common/export-utilities';
22
import { yieldingLoop } from '../../core/utils';
3-
import { IColumnInfo } from '../exporter-common/base-export-service';
3+
import { ExportHeaderType, IColumnInfo } from '../exporter-common/base-export-service';
44

55
/**
66
* @hidden
@@ -43,7 +43,8 @@ export class CharSeparatedValueData {
4343
}
4444

4545
public prepareDataAsync(done: (result: string) => void) {
46-
const columns = this.columns?.filter(c => !c.skip)
46+
const columns = this.columns?.filter(c => c.headerType !== ExportHeaderType.MultiColumnHeader)
47+
.filter(c => !c.skip)
4748
.sort((a, b) => a.startIndex - b.startIndex)
4849
.sort((a, b) => a.pinnedIndex - b.pinnedIndex);
4950
const keys = columns && columns.length ? columns.map(c => c.field) : ExportUtilities.getKeysFromData(this._data);
@@ -52,7 +53,10 @@ export class CharSeparatedValueData {
5253
this._escapeCharacters.push(this._delimiter);
5354

5455
const headers = columns && columns.length ?
55-
columns.map(c => c.header ?? c.field) :
56+
/* When column groups are present, always use the field as it indicates the group the column belongs to.
57+
* Otherwise, in PivotGrid scenarios we can end up with many duplicated columns.
58+
*/
59+
columns.map(c => c.columnGroupParent ? c.field : c.header ?? c.field) :
5660
keys;
5761

5862
this._headerRecord = this.processHeaderRecord(headers, this._data.length);

0 commit comments

Comments
 (0)