Skip to content

Commit 310d1ba

Browse files
authored
Fixed Pivot grid export to excel with hierarchical row dimensions. (#15806)
* fix(ExcelExport): Fixed hierarchical row dimensions export.
1 parent a5b866b commit 310d1ba

File tree

6 files changed

+315
-49
lines changed

6 files changed

+315
-49
lines changed

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

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ import { IgxHierarchicalGridExportComponent,
4848
import { IgxHierarchicalGridComponent } from '../../grids/hierarchical-grid/public_api';
4949
import { IgxHierarchicalRowComponent } from '../../grids/hierarchical-grid/hierarchical-row.component';
5050
import { GridFunctions } from '../../test-utils/grid-functions.spec';
51-
import { IgxPivotGridMultipleRowComponent, IgxPivotGridTestComplexHierarchyComponent } from '../../test-utils/pivot-grid-samples.spec';
52-
import { IgxPivotGridComponent, PivotRowLayoutType } from '../../grids/pivot-grid/public_api';
51+
import { IgxPivotGridMultipleRowComponent, IgxPivotGridTestComplexHierarchyComponent, SALES_DATA } from '../../test-utils/pivot-grid-samples.spec';
52+
import { IgxPivotGridComponent, IgxPivotNumericAggregate, PivotRowLayoutType } from '../../grids/pivot-grid/public_api';
5353

5454
describe('Excel Exporter', () => {
5555
configureTestSuite();
@@ -1458,7 +1458,7 @@ describe('Excel Exporter', () => {
14581458
let grid: IgxPivotGridComponent;
14591459

14601460
beforeEach(waitForAsync(() => {
1461-
options = createExportOptions('PivotGridGridExcelExport');
1461+
options = createExportOptions('PivotGridExcelExport');
14621462
}));
14631463

14641464
it('should export pivot grid', async () => {
@@ -1483,6 +1483,80 @@ describe('Excel Exporter', () => {
14831483
await exportAndVerify(grid, options, actualData.exportPivotGridDataWithHeaders, false);
14841484
});
14851485

1486+
it('should export pivot grid with hierarchical row dimensions.', async () => {
1487+
fix = TestBed.createComponent(IgxPivotGridMultipleRowComponent);
1488+
fix.detectChanges();
1489+
1490+
grid = fix.componentInstance.pivotGrid;
1491+
fix.componentInstance.data = SALES_DATA;
1492+
fix.componentInstance.pivotConfigHierarchy = {
1493+
rows: [
1494+
{
1495+
memberName: 'All_Srep Code Alts',
1496+
enabled: true,
1497+
width: '150px',
1498+
childLevel: {
1499+
memberName: 'SREP_CODE_ALT',
1500+
displayName: 'Srep Code Alt',
1501+
sortDirection: 1,
1502+
enabled: true,
1503+
},
1504+
},
1505+
{
1506+
memberName: 'All_Srep Codes',
1507+
enabled: true,
1508+
width: '150px',
1509+
childLevel: {
1510+
memberName: 'SREP_CODE',
1511+
displayName: 'Srep Code',
1512+
sortDirection: 1,
1513+
enabled: true,
1514+
},
1515+
},
1516+
{
1517+
memberName: 'All_Customers',
1518+
enabled: true,
1519+
width: '150px',
1520+
childLevel: {
1521+
memberName: 'CUST_CODE',
1522+
displayName: 'Customer',
1523+
sortDirection: 1,
1524+
enabled: true,
1525+
},
1526+
}
1527+
],
1528+
columns: [],
1529+
values: [
1530+
{
1531+
member: 'JOBS',
1532+
aggregate: {
1533+
key: 'Count of Jobs',
1534+
aggregator: IgxPivotNumericAggregate.count,
1535+
label: 'Count of Jobs',
1536+
},
1537+
enabled: true,
1538+
dataType: 'number',
1539+
},
1540+
{
1541+
member: 'INV_SALES',
1542+
aggregate: {
1543+
key: 'Sum of Sales',
1544+
aggregator: IgxPivotNumericAggregate.sum,
1545+
label: 'Sum of Sales',
1546+
},
1547+
enabled: true,
1548+
dataType: 'number',
1549+
},
1550+
],
1551+
filters: [],
1552+
};
1553+
grid.pivotUI.showRowHeaders = true;
1554+
fix.detectChanges();
1555+
await wait(300);
1556+
1557+
await exportAndVerify(grid, options, actualData.exportPivotGridHierarchicalRowDimensions, false);
1558+
});
1559+
14861560
it('should export hierarchical pivot grid', async () => {
14871561
fix = TestBed.createComponent(IgxPivotGridTestComplexHierarchyComponent);
14881562
fix.detectChanges();

projects/igniteui-angular/src/lib/services/excel/excel-files.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ export class WorksheetFile implements IExcelFile {
632632
for (const currentCol of headersForLevel) {
633633
const spanLength = isVertical ? currentCol.rowSpan : currentCol.columnSpan;
634634

635-
if (currentCol.level === i && currentCol.headerType !== ExportHeaderType.PivotMergedHeader) {
635+
if (currentCol.level === i) {
636636
let columnCoordinate;
637637
const column = isVertical
638638
? this.rowIndex
@@ -644,7 +644,10 @@ export class WorksheetFile implements IExcelFile {
644644
if (currentCol.headerType === ExportHeaderType.PivotRowHeader) {
645645
rowCoordinate = startValue + 1;
646646
}
647-
const columnValue = dictionary.saveValue(currentCol.header, true, false);
647+
648+
const columnValue = currentCol.headerType === ExportHeaderType.PivotMergedHeader ?
649+
dictionary.saveValue(currentCol.field, true, true) :
650+
dictionary.saveValue(currentCol.header, true, false);
648651

649652
columnCoordinate = (currentCol.field === GRID_LEVEL_COL
650653
? ExcelStrings.getExcelColumn(worksheetData.columnCount + 1)

0 commit comments

Comments
 (0)