Skip to content

Commit 43440d6

Browse files
authored
[CSV] Always print column headers if available. (#16596)
1 parent 3adfe66 commit 43440d6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ export class CharSeparatedValueData {
5252
this._escapeCharacters.push(this._delimiter);
5353

5454
const headers = columns && columns.length ?
55-
/* When column groups are present, always use the field as it indicates the group the column belongs to.
56-
* Otherwise, in PivotGrid scenarios we can end up with many duplicated column names without a hint what they represent.
57-
*/
58-
columns.map(c => c.columnGroupParent ? c.field : c.header ?? c.field) :
55+
columns.map(c => c.header ?? c.field) :
5956
keys;
6057

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

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { wait } from '../../test-utils/ui-interactions.spec';
2424
import { IgxPivotGridComponent } from '../../grids/pivot-grid/pivot-grid.component';
2525
import { IgxPivotGridTestBaseComponent } from '../../test-utils/pivot-grid-samples.spec';
2626
import { IgxPivotNumericAggregate } from '../../grids/pivot-grid/pivot-grid-aggregate';
27+
import { OneGroupThreeColsGridComponent } from '../../test-utils/grid-mch-sample.spec';
2728

2829
describe('CSV Grid Exporter', () => {
2930
let exporter: IgxCsvExporterService;
@@ -391,6 +392,20 @@ describe('CSV Grid Exporter', () => {
391392
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
392393
});
393394

395+
it('should print column headers when available when column groups are present.', async () => {
396+
const fix = TestBed.createComponent(OneGroupThreeColsGridComponent);
397+
fix.componentInstance.data = [];
398+
fix.detectChanges();
399+
400+
fix.componentInstance.grid.getColumnByName('City').header = 'Test Header';
401+
fix.detectChanges();
402+
403+
const grid = fix.componentInstance.grid;
404+
405+
const wrapper = await getExportedData(grid, options);
406+
wrapper.verifyData('Country,Region,Test Header', 'Only headers should be exported.');
407+
});
408+
394409
describe('Tree Grid CSV export', () => {
395410
let fix;
396411
let treeGrid: IgxTreeGridComponent;

0 commit comments

Comments
 (0)