Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,49 @@ describe('Excel Exporter', () => {
await exportAndVerify(hGrid, options, actualData.exportHierarchicalDataWithExpandedRows);
});

it('should export hierarchical grid with expanded rows when using primaryKey', async () => {
hGrid.primaryKey = 'Artist';
fix.detectChanges();

const firstRow = hGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
const secondRow = hGrid.gridAPI.get_row_by_index(1) as IgxHierarchicalRowComponent;

UIInteractions.simulateClickAndSelectEvent(firstRow.expander);
fix.detectChanges();
expect(firstRow.expanded).toBe(true);

let childGrids = hGrid.gridAPI.getChildGrids(false);

const firstChildGrid = childGrids[0];
const firstChildRow = firstChildGrid.gridAPI.get_row_by_index(2) as IgxHierarchicalRowComponent;

UIInteractions.simulateClickAndSelectEvent(firstChildRow.expander);
fix.detectChanges();
expect(firstChildRow.expanded).toBe(true);

const secondChildGrid = childGrids[1];
const secondChildRow = secondChildGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;

UIInteractions.simulateClickAndSelectEvent(secondChildRow.expander);
fix.detectChanges();
expect(secondChildRow.expanded).toBe(true);

UIInteractions.simulateClickAndSelectEvent(secondRow.expander);
fix.detectChanges();
expect(secondRow.expanded).toBe(true);

childGrids = hGrid.gridAPI.getChildGrids(false);

const thirdChildGrid = childGrids[3];
const thirdChildRow = thirdChildGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;

UIInteractions.simulateClickAndSelectEvent(thirdChildRow.expander);
fix.detectChanges();
expect(thirdChildRow.expanded).toBe(true);

await exportAndVerify(hGrid, options, actualData.exportHierarchicalDataWithExpandedRows);
});

it('should export hierarchical grid data with frozen headers', async () => {
options.freezeHeaders = true;
fix.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,8 @@ export abstract class IgxBaseExporter {
const columnFields = this._ownersMap.get(grid).columns.map(col => col.field);

for (const entry of records) {
const expansionStateVal = grid.expansionStates.has(entry) ? grid.expansionStates.get(entry) : grid.getDefaultExpandState(entry);
const rowKey = grid.primaryKey ? entry[grid.primaryKey] : entry;
const expansionStateVal = grid.expansionStates.has(rowKey) ? grid.expansionStates.get(rowKey) : grid.getDefaultExpandState(entry);

const dataWithoutChildren = Object.keys(entry)
.filter(k => columnFields.includes(k))
Expand All @@ -653,8 +654,8 @@ export abstract class IgxBaseExporter {

for (const island of childLayoutList) {
const path: IPathSegment = {
rowID: island.primaryKey ? entry[island.primaryKey] : entry,
rowKey: island.primaryKey ? entry[island.primaryKey] : entry,
rowID: grid.primaryKey ? entry[grid.primaryKey] : entry,
rowKey: grid.primaryKey ? entry[grid.primaryKey] : entry,
rowIslandKey: island.key
};

Expand Down Expand Up @@ -793,24 +794,27 @@ export abstract class IgxBaseExporter {
this.flatRecords.push(exportRecord);

if (island.children.length > 0) {
const islandRowKey = grid?.primaryKey ? rec[grid.primaryKey] : rec;
const islandExpansionStateVal = grid === undefined ?
false :
grid.expansionStates.has(rec) ?
grid.expansionStates.get(rec) :
grid.expansionStates.has(islandRowKey) ?
grid.expansionStates.get(islandRowKey) :
false;

for (const childIsland of island.children) {
const path: IPathSegment = {
rowID: childIsland.primaryKey ? rec[childIsland.primaryKey] : rec,
rowKey: childIsland.primaryKey ? rec[childIsland.primaryKey] : rec,
rowID: grid?.primaryKey ? rec[grid.primaryKey] : rec,
rowKey: grid?.primaryKey ? rec[grid.primaryKey] : rec,
rowIslandKey: childIsland.key
};

// only defined when row is expanded in UI
const childIslandGrid = grid?.gridAPI.getChildGrid([path]);
const keyRecordData = this.prepareIslandData(island, childIslandGrid, rec[childIsland.key]) || [];

this.getAllChildColumnsAndData(childIsland, keyRecordData, islandExpansionStateVal, childIslandGrid);
// Children should only be visible if both parent and current row are expanded
const combinedExpansionState = expansionStateVal && islandExpansionStateVal;
this.getAllChildColumnsAndData(childIsland, keyRecordData, combinedExpansionState, childIslandGrid);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,46 @@ describe('PDF Grid Exporter', () => {
exporter.export(hGrid, options);
});

it('should export hierarchical grid with expanded rows when using primaryKey', (done) => {
const fix = TestBed.createComponent(IgxHierarchicalGridExportComponent);
fix.detectChanges();

const hGrid = fix.componentInstance.hGrid;

// Set primary key on the grid
hGrid.primaryKey = 'Artist';
fix.detectChanges();

// Limit data for test performance
hGrid.data = hGrid.data.slice(0, 1);
fix.detectChanges();

const firstRowData = hGrid.data[0];

hGrid.toggleRow(firstRowData['Artist']);
fix.detectChanges();

expect(hGrid.expansionStates.get(firstRowData['Artist'])).toBe(true);

const childGrids = hGrid.gridAPI.getChildGrids(false) as any[];
expect(childGrids.length).toBeGreaterThan(0);

const firstChildGrid = childGrids[0];
expect(firstChildGrid.data.length).toBeGreaterThan(0);

// Spy on drawDataRow to count exported rows
const drawDataRowSpy = spyOn<any>(exporter as any, 'drawDataRow').and.callThrough();

exporter.exportEnded.pipe(first()).subscribe(() => {
const minExpectedRows = 1 + firstChildGrid.data.length;
expect(drawDataRowSpy.calls.count()).toBeGreaterThanOrEqual(minExpectedRows,
'Child rows should be exported when parent is expanded via toggleRow with primaryKey');
done();
});

exporter.export(hGrid, options);
});

it('should export tree grid with hierarchical data', (done) => {
TestBed.configureTestingModule({
imports: [
Expand Down
Loading