Skip to content

Commit

Permalink
Merge branch '7.2.x' into mkirova/fix-4447
Browse files Browse the repository at this point in the history
  • Loading branch information
mpavlinov authored Apr 4, 2019
2 parents fd71922 + b359762 commit 83d0d4f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 26 deletions.
10 changes: 7 additions & 3 deletions projects/igniteui-angular/src/lib/grids/grid-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,10 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
if (this._height !== value) {
this._height = value;
requestAnimationFrame(() => {
this.reflow();
this.cdr.markForCheck();
if (!this._destroyed) {
this.reflow();
this.cdr.markForCheck();
}
});
}
}
Expand Down Expand Up @@ -594,7 +596,9 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
// Calling reflow(), because the width calculation
// might make the horizontal scrollbar appear/disappear.
// This will change the height, which should be recalculated.
this.reflow();
if (!this._destroyed) {
this.reflow();
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
});
this.hGrid.parent = this.parentGrid;
this.hGrid.parentIsland = this.layout;
this.hGrid.childRow = this;
this.layout.onGridCreated.emit({
owner: this.layout,
parentID: this.rowData.rowID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { IgxHierarchicalSelectionAPIService } from './selection';
import { IgxHierarchicalGridNavigationService } from './hierarchical-grid-navigation.service';
import { IgxGridSummaryService } from '../summaries/grid-summary.service';
import { IgxGridSelectionService, IgxGridCRUDService } from '../../core/grid-selection';
import { IgxChildGridRowComponent } from './child-grid-row.component';

export const IgxHierarchicalTransactionServiceFactory = {
provide: IgxGridTransaction,
Expand Down Expand Up @@ -71,6 +72,11 @@ export abstract class IgxHierarchicalGridBaseComponent extends IgxGridBaseCompon
*/
public parentIsland: IgxRowIslandComponent;

/**
* @hidden
*/
public childRow: IgxChildGridRowComponent;

protected _expandChildren = false;

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
AfterViewInit,
AfterContentInit,
Optional,
OnInit
OnInit,
OnDestroy
} from '@angular/core';
import { IgxGridBaseComponent, IgxGridTransaction } from '../grid-base.component';
import { GridBaseAPIService } from '../api.service';
Expand Down Expand Up @@ -64,7 +65,7 @@ export interface HierarchicalStateRecord {
]
})
export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseComponent
implements IGridDataBindable, AfterViewInit, AfterContentInit, OnInit {
implements IGridDataBindable, AfterViewInit, AfterContentInit, OnInit, OnDestroy {
private _overlayIDs = [];
/**
* Sets the value of the `id` attribute. If not provided it will be automatically generated.
Expand Down Expand Up @@ -432,6 +433,17 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseCompone
}
}

ngOnDestroy() {
if (!this.parent) {
this.hgridAPI.getChildGrids(true).forEach((grid) => {
if (!grid.childRow.cdr.destroyed) {
grid.childRow.cdr.destroy();
}
});
}
super.ngOnDestroy();
}

/**
* @hidden
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ describe('IgxHierarchicalGrid Complex Navigation', () => {
expect(nextCell.rowIndex).toBe(2);
}));

xit('should allow navigating up from parent into nested child grid', (async () => {
it('should allow navigating up from parent into nested child grid', (async () => {
hierarchicalGrid.verticalScrollContainer.scrollTo(2);
await wait(100);
fixture.detectChanges();
Expand Down Expand Up @@ -777,12 +777,6 @@ describe('IgxHierarchicalGrid Complex Navigation', () => {
expect(lastCell.rowIndex).toBe(4);

}));

xit('ViewDestroyedError: Attempt to use a destroyed view trigger', (async () => {
// Repro for leftover un-destroyed grid views (leaked resize handler):
// fit this and the test above
window.dispatchEvent(new Event('resize'));
}));
});

describe('IgxHierarchicalGrid Multi-layout Navigation', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,32 @@ describe('IgxHierarchicalGrid Row Islands', () => {
hVirt = childGrid.getRowByIndex(0).virtDirRow;
expect(hVirt.getHorizontalScroll().scrollWidth).toBe(272);
}));

it('should destroy cached instances of child grids when root grid is destroyed', (async () => {
const row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
UIInteractions.clickElement(row.expander);
fixture.detectChanges();

const children = hierarchicalGrid.hgridAPI.getChildGrids(true);
expect(children.length).toBe(2);
const child1 = children[0];
const child2 = children[1];
expect(child1._destroyed).toBeFalsy();
expect(child2._destroyed).toBeFalsy();
hierarchicalGrid.verticalScrollContainer.scrollTo(hierarchicalGrid.verticalScrollContainer.igxForOf.length - 1);
await wait(100);
fixture.detectChanges();

// check that we have child is not destroyed
expect(child1._destroyed).toBeFalsy();
expect(child2._destroyed).toBeFalsy();

// destroy hgrid
fixture.destroy();

expect(child1._destroyed).toBeTruthy();
expect(child2._destroyed).toBeTruthy();
}));
});

describe('IgxHierarchicalGrid Remote Scenarios', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { wait } from '../../test-utils/ui-interactions.spec';
import { FilteringExpressionsTree, FilteringLogic, IgxStringFilteringOperand } from 'igniteui-angular';
import { By } from '@angular/platform-browser';
import { first, delay } from 'rxjs/operators';
import { setupHierarchicalGridScrollDetection } from '../../test-utils/helper-utils.spec';

describe('IgxHierarchicalGrid Virtualization', () => {
configureTestSuite();
Expand Down Expand Up @@ -84,47 +85,45 @@ describe('IgxHierarchicalGrid Virtualization', () => {
await wait(3 * 16);
});

xit('Should retain child grid states (scroll position, selection, filtering, paging etc.) when scrolling', fakeAsync(() => {
it('Should retain child grid states (scroll position, selection, filtering, paging etc.) when scrolling', async () => {
setupHierarchicalGridScrollDetection(fixture, hierarchicalGrid);
const firstRow = hierarchicalGrid.dataRowList.toArray()[0];
// first child of the row should expand indicator
firstRow.nativeElement.children[0].click();
fixture.detectChanges();

const childGrid = hierarchicalGrid.hgridAPI.getChildGrids(false)[0];
const childCell = childGrid.dataRowList.toArray()[4].cells.toArray()[0];
const childCell = childGrid.getCellByColumn(0, 'ID');
childCell.nativeElement.focus();
tick(10);
fixture.detectChanges();

const filteringExpressionsTree = new FilteringExpressionsTree(FilteringLogic.And, 'ProductName');
const expression = {
fieldName: 'ProductName',
searchVal: 'Product: A4',
searchVal: 'Product: A0',
condition: IgxStringFilteringOperand.instance().condition('startsWith')
};
filteringExpressionsTree.filteringOperands.push(expression);
childGrid.filter('ProductName', null, filteringExpressionsTree);
tick();
await wait();
fixture.detectChanges();
expect(childGrid.rowList.length).toEqual(1);
expect(childGrid.rowList.toArray()[0].cells.toArray()[0].selected).toBeTruthy();
expect(childGrid.getCellByColumn(0, 'ID').selected).toBeTruthy();

const verticalScroll = fixture.componentInstance.hgrid.verticalScrollContainer;
const elem = verticalScroll['vh'].instance.elementRef.nativeElement;
// scroll down
elem.scrollTop = 1000;
fixture.detectChanges();
fixture.componentRef.hostView.detectChanges();
tick();
await wait();


// scroll to top
elem.scrollTop = 0;
fixture.detectChanges();
fixture.componentRef.hostView.detectChanges();
tick();
await wait();

expect(childGrid.rowList.length).toEqual(1);
expect(childGrid.rowList.toArray()[0].cells.toArray()[0].selected).toBeTruthy();
}));
expect(childGrid.getCellByColumn(0, 'ID').selected).toBeTruthy();
});

it('should render correct data for child grid after scrolling and start index changes.', async() => {
const firstRow = hierarchicalGrid.dataRowList.toArray()[0];
Expand Down

0 comments on commit 83d0d4f

Please sign in to comment.