Skip to content

Commit 07e1eae

Browse files
authored
Merge branch 'master' into mkirova/fix-5039-master
2 parents 806ec3f + 2734508 commit 07e1eae

File tree

6 files changed

+107
-50
lines changed

6 files changed

+107
-50
lines changed

projects/igniteui-angular/src/lib/grids/grid-base.component.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,49 +1986,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
19861986
this.cdr.markForCheck();
19871987
}
19881988

1989-
/**
1990-
* Returns the state of the grid virtualization, including the start index and how many records are rendered.
1991-
* ```typescript
1992-
* const gridVirtState = this.grid1.virtualizationState;
1993-
* ```
1994-
* @memberof IgxGridBaseComponent
1995-
*/
1996-
get virtualizationState() {
1997-
return this.verticalScrollContainer.state;
1998-
}
1999-
2000-
/**
2001-
* @hidden
2002-
*/
2003-
set virtualizationState(state) {
2004-
this.verticalScrollContainer.state = state;
2005-
}
2006-
2007-
/**
2008-
* Returns the total number of records in the data source.
2009-
* Works only with remote grid virtualization.
2010-
* ```typescript
2011-
* const itemCount = this.grid1.totalItemCount;
2012-
* ```
2013-
* @memberof IgxGridBaseComponent
2014-
*/
2015-
get totalItemCount() {
2016-
return this.verticalScrollContainer.totalItemCount;
2017-
}
2018-
2019-
/**
2020-
* Sets the total number of records in the data source.
2021-
* This property is required for virtualization to function when the grid is bound remotely.
2022-
* ```typescript
2023-
* this.grid1.totalItemCount = 55;
2024-
* ```
2025-
* @memberof IgxGridBaseComponent
2026-
*/
2027-
set totalItemCount(count) {
2028-
this.verticalScrollContainer.totalItemCount = count;
2029-
this.cdr.detectChanges();
2030-
}
2031-
20321989
/**
20331990
* @hidden
20341991
*/
@@ -4041,7 +3998,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
40413998
* @hidden
40423999
*/
40434000
protected get defaultTargetBodyHeight(): number {
4044-
const allItems = this.totalItemCount || this.dataLength;
4001+
const allItems = this.dataLength;
40454002
return this.renderedRowHeight * Math.min(this._defaultTargetRecordNumber,
40464003
this.paging ? Math.min(allItems, this.perPage) : allItems);
40474004
}

projects/igniteui-angular/src/lib/grids/grid/grid.component.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class IgxGridComponent extends IgxGridBaseComponent implements IGridDataB
117117
* ```html
118118
* <igx-grid [data]="Data" [autoGenerate]="true"></igx-grid>
119119
* ```
120-
* @memberof IgxGridBaseComponent
120+
* @memberof IgxGridComponent
121121
*/
122122
@Input()
123123
public get data(): any[] {
@@ -163,6 +163,49 @@ export class IgxGridComponent extends IgxGridBaseComponent implements IGridDataB
163163
}
164164
}
165165

166+
/**
167+
* Returns the state of the grid virtualization, including the start index and how many records are rendered.
168+
* ```typescript
169+
* const gridVirtState = this.grid1.virtualizationState;
170+
* ```
171+
* @memberof IgxGridComponent
172+
*/
173+
get virtualizationState() {
174+
return this.verticalScrollContainer.state;
175+
}
176+
177+
/**
178+
* @hidden
179+
*/
180+
set virtualizationState(state) {
181+
this.verticalScrollContainer.state = state;
182+
}
183+
184+
/**
185+
* Sets the total number of records in the data source.
186+
* This property is required for remote grid virtualization to function when it is bound to remote data.
187+
* ```typescript
188+
* this.grid1.totalItemCount = 55;
189+
* ```
190+
* @memberof IgxGridComponent
191+
*/
192+
set totalItemCount(count) {
193+
this.verticalScrollContainer.totalItemCount = count;
194+
this.cdr.detectChanges();
195+
}
196+
197+
/**
198+
* Returns the total number of records in the data source.
199+
* Works only with remote grid virtualization.
200+
* ```typescript
201+
* const itemCount = this.grid1.totalItemCount;
202+
* ```
203+
* @memberof IgxGridComponent
204+
*/
205+
get totalItemCount() {
206+
return this.verticalScrollContainer.totalItemCount;
207+
}
208+
166209
private _gridAPI: IgxGridAPIService;
167210
private _filteredData = null;
168211

@@ -780,6 +823,15 @@ export class IgxGridComponent extends IgxGridBaseComponent implements IGridDataB
780823
}
781824
}
782825

826+
/**
827+
* @hidden
828+
*/
829+
protected get defaultTargetBodyHeight(): number {
830+
const allItems = this.totalItemCount || this.dataLength;
831+
return this.renderedRowHeight * Math.min(this._defaultTargetRecordNumber,
832+
this.paging ? Math.min(allItems, this.perPage) : allItems);
833+
}
834+
783835
/**
784836
* @hidden
785837
*/

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid-navigation.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,17 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
455455
const cell = cells[0];
456456
const childContainer = this.grid.nativeElement.parentNode.parentNode;
457457
const scrTop = this.grid.parent.verticalScrollContainer.getVerticalScroll().scrollTop;
458+
const maxScroll = this.grid.parent.verticalScrollContainer.getVerticalScroll().scrollHeight - this.grid.parent.calcHeight;
458459
const dc = childContainer.parentNode.parentNode;
459460
const scrWith = parseInt(dc.style.top, 10);
460-
if (scrTop === 0 || scrWith === 0) {
461+
const parentRowOffset = childContainer.parentNode.offsetTop + this.grid.nativeElement.offsetTop +
462+
scrWith;
463+
if ((scrTop === 0 && parentRowOffset < 0 ) || parentRowOffset === 0 || (scrTop === maxScroll && parentRowOffset > 0)) {
461464
// cell is in view
462465
cell.focus({ preventScroll: true });
463466
} else {
464467
// scroll parent so that cell is in view
465-
this.scrollGrid(this.grid.parent, scrWith, () => cell.focus({ preventScroll: true }));
468+
this.scrollGrid(this.grid.parent, parentRowOffset, () => cell.focus({ preventScroll: true }));
466469
}
467470
}
468471

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseCompone
671671

672672
const childGrids = this.getChildGrids(true);
673673
childGrids.forEach((grid) => {
674+
if (grid.isPercentWidth) {
675+
grid.reflow();
676+
}
674677
grid.updateScrollPosition();
675678
});
676679
}

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.navigation.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ describe('IgxHierarchicalGrid Basic Navigation', () => {
274274
expect(childCell.rowIndex).toBe(0);
275275

276276
const currScrTop = hierarchicalGrid.verticalScrollContainer.getVerticalScroll().scrollTop;
277-
expect(currScrTop).toBeLessThanOrEqual(childGrid.rowHeight + 1);
277+
const childGridOffset = childGrid.nativeElement.offsetTop;
278+
expect(currScrTop).toBeLessThanOrEqual(childGrid.rowHeight + 1 + childGridOffset);
278279
}));
279280

280281
it('should allow navigating to bottom in child grid when child grid target row moves outside the parent view port.', (async () => {
@@ -349,7 +350,29 @@ describe('IgxHierarchicalGrid Basic Navigation', () => {
349350
expect(childFirstRowCell.rowIndex).toBe(0);
350351

351352
const currScrTop = hierarchicalGrid.verticalScrollContainer.getVerticalScroll().scrollTop;
352-
expect(currScrTop).toBeLessThanOrEqual(childGrid.rowHeight + 1);
353+
const childGridOffset = childGrid.nativeElement.offsetTop;
354+
expect(currScrTop).toBeLessThanOrEqual(childGrid.rowHeight + 1 + childGridOffset);
355+
}));
356+
357+
it('should scroll top of child grid into view when pressing Ctrl + Arrow Up when cell is selected in it.', (async () => {
358+
hierarchicalGrid.verticalScrollContainer.scrollTo(3);
359+
await wait(100);
360+
fixture.detectChanges();
361+
362+
const childGrid = hierarchicalGrid.hgridAPI.getChildGrids(false)[3];
363+
const childLastRowCell = childGrid.dataRowList.toArray()[9].cells.toArray()[0];
364+
childLastRowCell.nativeElement.focus();
365+
fixture.detectChanges();
366+
childLastRowCell.nativeElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp', ctrlKey: true }));
367+
await wait(100);
368+
fixture.detectChanges();
369+
const childFirstRowCell = childGrid.dataRowList.toArray()[0].cells.toArray()[0];
370+
expect(childFirstRowCell.selected).toBe(true);
371+
expect(childFirstRowCell.columnIndex).toBe(0);
372+
expect(childFirstRowCell.rowIndex).toBe(0);
373+
374+
const currScrTop = hierarchicalGrid.verticalScrollContainer.getVerticalScroll().scrollTop;
375+
expect(currScrTop).toBeGreaterThanOrEqual(2000);
353376
}));
354377

355378
it('when navigating down from parent into child should scroll child grid to top and start navigation from first row.', (async () => {

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.spec.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,24 @@ describe('Basic IgxHierarchicalGrid', () => {
268268
expect(hierarchicalGrid.nativeElement.classList.contains('igx-grid--compact')).toBe(true);
269269
expect(childGrid.displayDensity).toBe(DisplayDensity.compact);
270270
}));
271+
272+
it('when child width is in percents its width should be update if parent width changes while parent row is collapsed. ', async () => {
273+
const row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
274+
UIInteractions.clickElement(row.expander);
275+
fixture.detectChanges();
276+
const childGrids = fixture.debugElement.queryAll(By.css('igx-child-grid-row'));
277+
const childGrid = childGrids[0].query(By.css('igx-hierarchical-grid')).componentInstance;
278+
expect(childGrid.calcWidth - 370).toBeLessThan(3);
279+
UIInteractions.clickElement(row.expander);
280+
fixture.detectChanges();
281+
fixture.componentInstance.width = '300px';
282+
fixture.detectChanges();
283+
await wait(30);
284+
fixture.detectChanges();
285+
UIInteractions.clickElement(row.expander);
286+
fixture.detectChanges();
287+
expect(childGrid.calcWidth - 170).toBeLessThan(3);
288+
});
271289
});
272290

273291
describe('IgxHierarchicalGrid Row Islands', () => {
@@ -944,7 +962,7 @@ describe('IgxHierarchicalGrid Runtime Row Island change Scenarios', () => {
944962
@Component({
945963
template: `
946964
<igx-hierarchical-grid #grid1 [data]="data"
947-
[autoGenerate]="false" [height]="'400px'" [width]="'500px'" #hierarchicalGrid>
965+
[autoGenerate]="false" [height]="'400px'" [width]="width" #hierarchicalGrid>
948966
<igx-column field="ID"></igx-column>
949967
<igx-column field="ProductName"></igx-column>
950968
<igx-row-island [key]="'childData'" [autoGenerate]="false" #rowIsland>
@@ -960,6 +978,7 @@ describe('IgxHierarchicalGrid Runtime Row Island change Scenarios', () => {
960978
})
961979
export class IgxHierarchicalGridTestBaseComponent {
962980
public data;
981+
public width = '500px';
963982
@ViewChild('hierarchicalGrid', { read: IgxHierarchicalGridComponent, static: true }) public hgrid: IgxHierarchicalGridComponent;
964983
@ViewChild('rowIsland', { read: IgxRowIslandComponent, static: true }) public rowIsland: IgxRowIslandComponent;
965984
@ViewChild('rowIsland2', { read: IgxRowIslandComponent, static: true }) public rowIsland2: IgxRowIslandComponent;

0 commit comments

Comments
 (0)