Skip to content

Commit fda947e

Browse files
authored
[CSV] Always print column headers if available. (#16597)
1 parent 8694d53 commit fda947e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

projects/igniteui-angular/grids/core/src/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/grids/core/src/services/csv/csv-exporter-grid.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { IgxPivotGridComponent } from 'igniteui-angular/grids/pivot-grid';
2121
import { IgxGridNavigationService, IgxPivotNumericAggregate } from 'igniteui-angular/grids/core';
2222
import { DefaultSortingStrategy, FilteringExpressionsTree, FilteringLogic, IgxNumberFilteringOperand, IgxStringFilteringOperand, SortingDirection } from 'igniteui-angular/core';
2323
import { CSVWrapper } from './csv-verification-wrapper.spec';
24+
import { OneGroupThreeColsGridComponent } from '../../../../../test-utils/grid-mch-sample.spec';
2425

2526
describe('CSV Grid Exporter', () => {
2627
let exporter: IgxCsvExporterService;
@@ -388,6 +389,20 @@ describe('CSV Grid Exporter', () => {
388389
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
389390
});
390391

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

0 commit comments

Comments
 (0)