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 @@ -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 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