Skip to content

Commit d7a0e52

Browse files
onlyexeptionChronosSFkdinevigdmdimitrov
authored
Export Grid with summaries (#12027)
* feat(excel-exporter): include summaries in export * feat(excel-exporter): export summaries * feat(excel-exporter): export tGrid with summaries * feat(excel-exporter): export hGrid with summaries * chore(*): minor base-export refactoring * feat(excel-exporter): fix grouped grid summaries export * feat(excel-exporter): push latest hGrid summary export changes * feat(excel-exporter): fix summary coordinates calculation for t/hGrid * feat(excel-exporter): fix summary export functions * fix(excel-exporter): dont include lvl col in col count for non hGrids * feat(excel-export): fix min, max, earliest, latest * feat(excel-exporter): hide level column, remove commented lines * chore(*): fix property usage * chore(*): push tests and some bug fixes * chore(*): remove fit from test * chore(*): update test data * fix(excel-exporter): exclude summary records from formatting+set level correctly * fix(excel-exporter): export custom sumaries * feat(exporter): add grid export sample * chore(*): fix grid export samples+exporter options * feat(excel-exporte): format currency cols in styles xml * chore(*): push latest changes * chore(*): remove extra symbol * chore(*): update changelog * chore(*): export sample fix columns * feat(exporter): display currencies in summaries+fix date format * chore(*): fix failing test * fix(exporter): unsupported locale currencies fallback to numbers * chore(*): add currencyCol settings * chore(*): add missing import * chore(*): add currency tests configuration * chore(*): remove problematic tests Co-authored-by: Stamen Stoychev <[email protected]> Co-authored-by: Konstantin Dinev <[email protected]> Co-authored-by: igdmdimitrov <[email protected]> Co-authored-by: igdmdimitrov <[email protected]>
1 parent e98a3fc commit d7a0e52

23 files changed

+1968
-50
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ All notable changes for each version of this project will be documented in this
3030
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
3131
- **Behavioral Change** - When editing a row, `rowChangesCount` and `hiddenColumnsCount`would be displayed.
3232

33+
- `IgxExcelExporterService`
34+
- Added support for exporting grid summaries.
35+
- Columns of type `currency` will be formatted as currency in Excel based on grid's locale. Locale currency different than `USD`, `EUR`, `GBP`, `CNY` or `JPY` will result in exporting the column as number instead.
36+
3337
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`, `IgxPivotGrid`
3438
- Adding `Image` column data type
3539

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

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ import {
1818
MultiColumnHeadersExportComponent,
1919
GridWithEmptyColumnsComponent,
2020
ColumnsAddedOnInitComponent,
21-
GridWithThreeLevelsOfMultiColumnHeadersAndTwoRowsExportComponent
21+
GridWithThreeLevelsOfMultiColumnHeadersAndTwoRowsExportComponent,
22+
GroupedGridWithSummariesComponent,
23+
GridCurrencySummariesComponent
2224
} from '../../test-utils/grid-samples.spec';
2325
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
2426
import { first } from 'rxjs/operators';
2527
import { DefaultSortingStrategy, SortingDirection } from '../../data-operations/sorting-strategy';
2628
import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition';
2729
import { configureTestSuite } from '../../test-utils/configure-suite';
28-
import { IgxTreeGridPrimaryForeignKeyComponent } from '../../test-utils/tree-grid-components.spec';
30+
import { IgxTreeGridPrimaryForeignKeyComponent, IgxTreeGridSummariesKeyComponent } from '../../test-utils/tree-grid-components.spec';
2931
import { IgxTreeGridModule, IgxTreeGridComponent } from '../../grids/tree-grid/public_api';
3032
import { IgxNumberFilteringOperand } from '../../data-operations/filtering-condition';
3133
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
@@ -34,7 +36,8 @@ import { FilteringExpressionsTree } from '../../data-operations/filtering-expres
3436
import { FilteringLogic } from '../../data-operations/filtering-expression.interface';
3537
import { IgxHierarchicalGridExportComponent,
3638
IgxHierarchicalGridMultiColumnHeaderIslandsExportComponent,
37-
IgxHierarchicalGridMultiColumnHeadersExportComponent
39+
IgxHierarchicalGridMultiColumnHeadersExportComponent,
40+
IgxHierarchicalGridSummariesExportComponent
3841
} from '../../test-utils/hierarchical-grid-components.spec';
3942
import { IgxHierarchicalGridModule,
4043
IgxHierarchicalGridComponent,
@@ -68,7 +71,11 @@ describe('Excel Exporter', () => {
6871
IgxHierarchicalGridMultiColumnHeaderIslandsExportComponent,
6972
GridWithThreeLevelsOfMultiColumnHeadersAndTwoRowsExportComponent,
7073
IgxPivotGridMultipleRowComponent,
71-
IgxPivotGridTestComplexHierarchyComponent
74+
IgxPivotGridTestComplexHierarchyComponent,
75+
IgxTreeGridSummariesKeyComponent,
76+
IgxHierarchicalGridSummariesExportComponent,
77+
GroupedGridWithSummariesComponent,
78+
GridCurrencySummariesComponent
7279
],
7380
imports: [IgxGridModule, IgxTreeGridModule, IgxHierarchicalGridModule, IgxPivotGridModule, NoopAnimationsModule]
7481
}).compileComponents();
@@ -1211,6 +1218,97 @@ describe('Excel Exporter', () => {
12111218
});
12121219
});
12131220

1221+
1222+
describe('', () => {
1223+
let fix;
1224+
let grid: any;
1225+
1226+
beforeEach(waitForAsync(() => {
1227+
options = createExportOptions('GirdSummariesExcelExport', 50);
1228+
}));
1229+
1230+
it('should export grid with summaries based on summaryCalculationMode', async () => {
1231+
fix = TestBed.createComponent(GroupedGridWithSummariesComponent);
1232+
fix.detectChanges();
1233+
await wait(300);
1234+
1235+
grid = fix.componentInstance.grid;
1236+
grid.summaryCalculationMode = 'rootLevelOnly';
1237+
1238+
await exportAndVerify(grid, options, actualData.exportGridWithSummaries);
1239+
1240+
(grid as IgxGridComponent).groupBy({ fieldName: 'Shipped', dir: SortingDirection.Asc, ignoreCase: false });
1241+
(grid as IgxGridComponent).groupBy({ fieldName: 'City', dir: SortingDirection.Asc, ignoreCase: false });
1242+
(grid as IgxGridComponent).groupBy({ fieldName: 'ContactTitle', dir: SortingDirection.Asc, ignoreCase: false });
1243+
1244+
fix.detectChanges();
1245+
1246+
await exportAndVerify(grid, options, actualData.exportGroupedGridWithSummariesRootLevelOnly);
1247+
1248+
grid.summaryCalculationMode = 'childLevelsOnly';
1249+
fix.detectChanges();
1250+
1251+
await exportAndVerify(grid, options, actualData.exportGroupedGridWithSummariesChildLevelsOnly);
1252+
1253+
grid.summaryCalculationMode = 'rootAndChildLevels';
1254+
fix.detectChanges();
1255+
1256+
await exportAndVerify(grid, options, actualData.exportGroupedGridWithSummariesRootAndChildLevels);
1257+
});
1258+
1259+
it('should export tree grid with summaries', async () => {
1260+
fix = TestBed.createComponent(IgxTreeGridSummariesKeyComponent);
1261+
fix.detectChanges();
1262+
await wait(300);
1263+
grid = fix.componentInstance.treeGrid;
1264+
1265+
grid.toggleRow(grid.getRowByIndex(2).key);
1266+
grid.toggleRow(grid.getRowByIndex(0).key);
1267+
grid.toggleRow(grid.getRowByIndex(3).key);
1268+
fix.detectChanges();
1269+
1270+
await exportAndVerify(grid, options, actualData.exportTreeGridWithSummaries);
1271+
});
1272+
1273+
it('should export hierarchical grid with summaries', async () => {
1274+
fix = TestBed.createComponent(IgxHierarchicalGridSummariesExportComponent);
1275+
fix.detectChanges();
1276+
await wait(300);
1277+
grid = fix.componentInstance.hGrid;
1278+
1279+
const firstRow = grid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
1280+
const secondRow = grid.gridAPI.get_row_by_index(1) as IgxHierarchicalRowComponent;
1281+
1282+
UIInteractions.simulateClickAndSelectEvent(firstRow.expander);
1283+
fix.detectChanges();
1284+
expect(firstRow.expanded).toBe(true);
1285+
1286+
let childGrids = grid.gridAPI.getChildGrids(false);
1287+
1288+
const firstChildGrid = childGrids[0];
1289+
const firstChildRow = firstChildGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
1290+
1291+
UIInteractions.simulateClickAndSelectEvent(firstChildRow.expander);
1292+
fix.detectChanges();
1293+
expect(firstChildRow.expanded).toBe(true);
1294+
1295+
UIInteractions.simulateClickAndSelectEvent(secondRow.expander);
1296+
fix.detectChanges();
1297+
expect(secondRow.expanded).toBe(true);
1298+
1299+
childGrids = grid.gridAPI.getChildGrids(false);
1300+
1301+
const thirdChildGrid = childGrids[1];
1302+
const thirdChildRow = thirdChildGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
1303+
1304+
UIInteractions.simulateClickAndSelectEvent(thirdChildRow.expander);
1305+
fix.detectChanges();
1306+
expect(thirdChildRow.expanded).toBe(true);
1307+
1308+
await exportAndVerify(grid, options, actualData.exportHierarchicalGridWithSummaries);
1309+
});
1310+
});
1311+
12141312
describe('', () => {
12151313
let fix;
12161314
let grid: IgxPivotGridComponent;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ExcelElementsFactory } from './excel-elements-factory';
55
import { ExcelFolderTypes } from './excel-enums';
66
import { IgxExcelExporterOptions } from './excel-exporter-options';
77
import { IExcelFolder } from './excel-interfaces';
8-
import { ExportRecordType, IExportRecord, IgxBaseExporter, DEFAULT_OWNER, HeaderType } from '../exporter-common/base-export-service';
8+
import { ExportRecordType, IExportRecord, IgxBaseExporter, DEFAULT_OWNER, HeaderType, GRID_LEVEL_COL } from '../exporter-common/base-export-service';
99
import { ExportUtilities } from '../exporter-common/export-utilities';
1010
import { WorksheetData } from './worksheet-data';
1111
import { IBaseEventArgs } from '../../core/utils';
@@ -114,7 +114,7 @@ export class IgxExcelExporterService extends IgxBaseExporter {
114114
defaultOwner = this._ownersMap.get(firstDataElement.owner);
115115
} else {
116116
defaultOwner = this._ownersMap.get(DEFAULT_OWNER);
117-
const columns = defaultOwner.columns.filter(col => !col.skip && col.headerType === HeaderType.ColumnHeader);
117+
const columns = defaultOwner.columns.filter(col => col.field !== GRID_LEVEL_COL && !col.skip && col.headerType === HeaderType.ColumnHeader);
118118

119119
columnWidths = defaultOwner.columnWidths;
120120
indexOfLastPinnedColumn = defaultOwner.indexOfLastPinnedColumn;
@@ -126,7 +126,7 @@ export class IgxExcelExporterService extends IgxBaseExporter {
126126

127127
defaultOwner = this._ownersMap.get(ownersKeys[0]);
128128
columnWidths = defaultOwner.columnWidths;
129-
columnCount = defaultOwner.columns.filter(col => !col.skip && col.headerType === HeaderType.ColumnHeader).length;
129+
columnCount = defaultOwner.columns.filter(col => col.field !== GRID_LEVEL_COL && !col.skip && col.headerType === HeaderType.ColumnHeader).length;
130130
}
131131

132132
const worksheetData =

0 commit comments

Comments
 (0)