Skip to content

Commit 10ddeef

Browse files
authored
Merge pull request #6400 from IgniteUI/ddincheva/columnwidthivy
Reduce the recalculation of featureColumnWidth
2 parents e620c05 + 15c8911 commit 10ddeef

File tree

11 files changed

+58
-96
lines changed

11 files changed

+58
-96
lines changed

projects/igniteui-angular/src/lib/grids/columns/column.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ export class IgxColumnComponent implements AfterContentInit {
17781778
const colWidth = this.width;
17791779
const isPercentageWidth = colWidth && typeof colWidth === 'string' && colWidth.indexOf('%') !== -1;
17801780
if (isPercentageWidth) {
1781-
this._calcWidth = parseInt(colWidth, 10) / 100 * (grid.calcWidth - grid.featureColumnsWidth);
1781+
this._calcWidth = parseInt(colWidth, 10) / 100 * (grid.calcWidth - grid.featureColumnsWidth());
17821782
} else if (!colWidth) {
17831783
// no width
17841784
this._calcWidth = this.defaultWidth || grid.getPossibleColumnWidth();

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

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
28342834
private _unpinnedWidth = NaN;
28352835
private _visibleColumns = [];
28362836
private _columnGroups = false;
2837+
protected _headerFeaturesWidth = NaN;
28372838

28382839
private _columnWidth: string;
28392840

@@ -3071,10 +3072,11 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
30713072
});
30723073

30733074
this.verticalScrollContainer.onContentSizeChange.pipe(destructor, filter(() => !this._init)).subscribe(($event) => {
3074-
this.calculateGridSizes();
3075+
this.calculateGridSizes(false);
30753076
});
30763077

30773078
this.onDensityChanged.pipe(destructor).subscribe(() => {
3079+
this._headerFeaturesWidth = NaN;
30783080
this.summaryService.summaryHeight = 0;
30793081
this.endEdit(true);
30803082
this.cdr.markForCheck();
@@ -3153,7 +3155,10 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
31533155
* @hidden
31543156
* @internal
31553157
*/
3156-
public resetCaches() {
3158+
public resetCaches(recalcFeatureWidth = true) {
3159+
if (recalcFeatureWidth) {
3160+
this._headerFeaturesWidth = NaN;
3161+
}
31573162
this.resetForOfCache();
31583163
this.resetColumnsCaches();
31593164
this.resetColumnCollections();
@@ -3418,17 +3423,26 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
34183423
/**
34193424
* @hidden
34203425
* Gets the combined width of the columns that are specific to the enabled grid features. They are fixed.
3421-
* TODO: Update for Angular 8. Calling parent class getter using super is not supported for now.
34223426
*/
3423-
public get featureColumnsWidth() {
3424-
return this.getFeatureColumnsWidth();
3427+
public featureColumnsWidth(expander?: ElementRef) {
3428+
if (Number.isNaN(this._headerFeaturesWidth)) {
3429+
const rowSelectArea = this.headerSelectorContainer ?
3430+
this.headerSelectorContainer.nativeElement.getBoundingClientRect().width : 0;
3431+
const rowDragArea = this.rowDraggable && this.headerDragContainer ?
3432+
this.headerDragContainer.nativeElement.getBoundingClientRect().width : 0;
3433+
const groupableArea = this.headerGroupContainer ?
3434+
this.headerGroupContainer.nativeElement.getBoundingClientRect().width : 0;
3435+
const expanderWidth = expander ? expander.nativeElement.getBoundingClientRect().width : 0;
3436+
this._headerFeaturesWidth = rowSelectArea + rowDragArea + groupableArea + expanderWidth;
3437+
}
3438+
return this._headerFeaturesWidth;
34253439
}
34263440

34273441
/**
34283442
* @hidden
34293443
*/
34303444
get summariesMargin() {
3431-
return this.featureColumnsWidth;
3445+
return this.featureColumnsWidth();
34323446
}
34333447

34343448
/**
@@ -4609,11 +4623,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
46094623
parseInt(this.document.defaultView.getComputedStyle(this.nativeElement).getPropertyValue('width'), 10);
46104624
}
46114625

4612-
computedWidth -= this.getFeatureColumnsWidth();
4613-
4614-
if (this.showDragIcons) {
4615-
computedWidth -= this.headerDragContainer ? this.headerDragContainer.nativeElement.offsetWidth : 0;
4616-
}
4626+
computedWidth -= this.featureColumnsWidth();
46174627

46184628
const visibleChildColumns = this.visibleColumns.filter(c => !c.columnGroup);
46194629

@@ -4703,7 +4713,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
47034713
return null;
47044714
}
47054715
this.cdr.detectChanges();
4706-
colSum += this.getFeatureColumnsWidth();
4716+
colSum += this.featureColumnsWidth();
47074717
return colSum;
47084718
}
47094719

@@ -4778,7 +4788,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
47784788
/**
47794789
* @hidden
47804790
*/
4781-
protected calculateGridSizes() {
4791+
protected calculateGridSizes(recalcFeatureWidth = true) {
47824792
/*
47834793
TODO: (R.K.) This layered lasagne should be refactored
47844794
ASAP. The reason I have to reset the caches so many times is because
@@ -4787,11 +4797,11 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
47874797
sizing process which of course, uses values from the caches, thus resulting
47884798
in a broken layout.
47894799
*/
4790-
this.resetCaches();
4800+
this.resetCaches(recalcFeatureWidth);
47914801
this.cdr.detectChanges();
47924802
const hasScroll = this.hasVerticalSroll();
47934803
this.calculateGridWidth();
4794-
this.resetCaches();
4804+
this.resetCaches(recalcFeatureWidth);
47954805
this.cdr.detectChanges();
47964806
this.calculateGridHeight();
47974807

@@ -4821,7 +4831,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
48214831
});
48224832
});
48234833
}
4824-
this.resetCaches();
4834+
this.resetCaches(recalcFeatureWidth);
48254835
}
48264836

48274837
private _applyWidthHostBinding() {
@@ -4838,25 +4848,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
48384848
this.cdr.markForCheck();
48394849
}
48404850

4841-
4842-
/**
4843-
* @hidden
4844-
* Gets the combined width of the columns that are specific to the enabled grid features. They are fixed.
4845-
* Method used to override the calculations.
4846-
* TODO: Remove for Angular 8. Calling parent class getter using super is not supported for now.
4847-
*/
4848-
public getFeatureColumnsWidth() {
4849-
let width = 0;
4850-
4851-
if (this.isRowSelectable) {
4852-
width += this.headerSelectorContainer ? this.headerSelectorContainer.nativeElement.getBoundingClientRect().width : 0;
4853-
}
4854-
if (this.rowDraggable) {
4855-
width += this.headerDragContainer ? this.headerDragContainer.nativeElement.getBoundingClientRect().width : 0;
4856-
}
4857-
return width;
4858-
}
4859-
48604851
/**
48614852
* Gets calculated width of the pinned area.
48624853
* ```typescript
@@ -4873,7 +4864,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
48734864
sum += parseInt(col.calcWidth, 10);
48744865
}
48754866
}
4876-
sum += this.featureColumnsWidth;
4867+
sum += this.featureColumnsWidth();
48774868

48784869
return sum;
48794870
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ describe('IgxGrid - Row Selection #grid', () => {
650650
grid = fix.componentInstance.grid;
651651
}));
652652

653-
it('Change RowSelection to multiple ', () => {
653+
it('Change RowSelection to multiple ', fakeAsync(() => {
654654
GridSelectionFunctions.verifyHeaderRowHasCheckbox(fix, false, false);
655655
GridSelectionFunctions.verifyRowHasCheckbox(grid.getRowByIndex(0).nativeElement, false, false);
656656

@@ -661,13 +661,15 @@ describe('IgxGrid - Row Selection #grid', () => {
661661

662662
grid.rowSelection = GridSelectionMode.multiple;
663663
fix.detectChanges();
664+
tick(100);
665+
fix.detectChanges();
664666

665667
GridSelectionFunctions.verifyHeaderAndRowCheckBoxesAlignment(grid);
666668
GridSelectionFunctions.verifyRowSelected(grid.getRowByIndex(0), false, false);
667669
GridSelectionFunctions.verifyHeaderRowCheckboxState(fix);
668670
GridSelectionFunctions.verifyHeaderRowHasCheckbox(fix);
669671
GridSelectionFunctions.verifyRowHasCheckbox(grid.getRowByIndex(0).nativeElement);
670-
});
672+
}));
671673
});
672674

673675
describe('RowSelection single', () => {
@@ -1548,7 +1550,7 @@ describe('IgxGrid - Row Selection #grid', () => {
15481550
grid.getColumnByName('ProductID').hasSummary = true;
15491551
fix.detectChanges();
15501552

1551-
expect(grid.summariesMargin).toBe(grid.featureColumnsWidth);
1553+
expect(grid.summariesMargin).toBe(grid.featureColumnsWidth());
15521554
});
15531555

15541556
it('Filtering: Should properly check the header checkbox state when filtering, #2469', () => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,8 +2362,8 @@ describe('IgxGrid - Summaries #grid', () => {
23622362
function verifySummaryRowIndentationByDataRowIndex(fixture, visibleIndex) {
23632363
const summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fixture, visibleIndex);
23642364
const summaryRowIndentation = summaryRow.query(By.css('.igx-grid__summaries-patch'));
2365-
const expander = fixture.componentInstance.grid.headerGroupContainer;
2366-
expect(summaryRowIndentation.nativeElement.offsetWidth).toEqual(expander.nativeElement.offsetWidth);
2365+
const grid = fixture.componentInstance.grid;
2366+
expect(summaryRowIndentation.nativeElement.offsetWidth).toEqual(grid.featureColumnsWidth());
23672367
}
23682368

23692369
function verifyBaseSummaries(fixture) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@
3333
<div class="igx-grid__tr" role="row" [style.width.px]='calcWidth'>
3434
<span *ngIf="hasMovableColumns && draggedColumn && pinnedColumns.length <= 0"
3535
[igxColumnMovingDrop]="headerContainer" [attr.droppable]="true" id="left"
36-
class="igx-grid__scroll-on-drag-left" [style.left.px]="featureColumnsWidth"></span>
36+
class="igx-grid__scroll-on-drag-left" [style.left.px]="pinnedWidth"></span>
3737
<span *ngIf="hasMovableColumns && draggedColumn && pinnedColumns.length > 0"
3838
[igxColumnMovingDrop]="headerContainer" [attr.droppable]="true" id="left"
3939
class="igx-grid__scroll-on-drag-pinned" [style.left.px]="pinnedWidth"></span>
40-
4140
<ng-container *ngIf="groupingExpressions.length > 0">
4241
<div class="igx-grid__header-indentation igx-grid__row-indentation--level-{{groupingExpressions.length}}"
4342
[ngClass]="{

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,21 +1139,6 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
11391139
return this.groupArea ? this.groupArea.nativeElement.offsetHeight : 0;
11401140
}
11411141

1142-
/**
1143-
* @hidden
1144-
* Gets the combined width of the columns that are specific to the enabled grid features. They are fixed.
1145-
* TODO: Remove for Angular 8. Calling parent class getter using super is not supported for now.
1146-
*/
1147-
public getFeatureColumnsWidth() {
1148-
let width = super.getFeatureColumnsWidth();
1149-
1150-
if (this.groupingExpressions.length && this.headerGroupContainer) {
1151-
width += this.headerGroupContainer.nativeElement.offsetWidth;
1152-
}
1153-
1154-
return width;
1155-
}
1156-
11571142
/**
11581143
* @hidden
11591144
*/
@@ -1243,6 +1228,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
12431228
this.onGroupingDone.pipe(takeUntil(this.destroy$)).subscribe((args) => {
12441229
this.endEdit(true);
12451230
this.summaryService.updateSummaryCache(args);
1231+
this._headerFeaturesWidth = NaN;
12461232
});
12471233
}
12481234

projects/igniteui-angular/src/lib/grids/grid/row-drag.directive.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,12 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
218218
it('should align horizontal scrollbar with first column when column pinning is disabled', fakeAsync(() => {
219219
// has no draggable and selectable rows
220220
grid.width = '400px';
221+
tick(30);
222+
fixture.detectChanges();
221223
grid.rowSelection = GridSelectionMode.none;
222224
grid.rowDraggable = false;
223-
tick();
225+
fixture.detectChanges();
226+
tick(30);
224227
fixture.detectChanges();
225228
let rowSelectElement: DebugElement = fixture.debugElement.query(By.css(CSS_CLASS_SELECTION_CHECKBOX));
226229
let dragIndicatorElement: DebugElement = fixture.debugElement.query(By.css('.' + CSS_CLASS_DRAG_INDICATOR));
@@ -231,7 +234,8 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
231234
// has draggable rows and has no selectable rows
232235
grid.rowSelection = GridSelectionMode.none;
233236
grid.rowDraggable = true;
234-
tick();
237+
fixture.detectChanges();
238+
tick(30);
235239
fixture.detectChanges();
236240
rowSelectElement = fixture.debugElement.query(By.css(CSS_CLASS_SELECTION_CHECKBOX));
237241
dragIndicatorElement = fixture.debugElement.query(By.css('.' + CSS_CLASS_DRAG_INDICATOR));

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<span *ngIf="hasMovableColumns && draggedColumn && pinnedColumns.length > 0"
1212
[igxColumnMovingDrop]="headerContainer" [attr.droppable]="true" id="left"
1313
class="igx-grid__scroll-on-drag-pinned" [style.left.px]="pinnedWidth"></span>
14-
<div #headerHierarchyExpander (click)="toggleAll()" [hidden]='!hasExpandableChildren || !hasVisibleColumns' [ngClass]="{
15-
'igx-grid__hierarchical-expander igx-grid__hierarchical-expander--header': hasExpandableChildren,
16-
'igx-grid__hierarchical-expander--push': filteringService.isFilterRowVisible,
17-
'igx-grid__hierarchical-expander--no-border': isRowSelectable || rowDraggable
18-
}">
14+
<div #headerHierarchyExpander (click)="toggleAll()" [hidden]='!hasExpandableChildren || !hasVisibleColumns' [ngClass]="{
15+
'igx-grid__hierarchical-expander igx-grid__hierarchical-expander--header': hasExpandableChildren,
16+
'igx-grid__hierarchical-expander--push': filteringService.isFilterRowVisible,
17+
'igx-grid__hierarchical-expander--no-border': isRowSelectable || rowDraggable
18+
}">
1919
<ng-container *ngTemplateOutlet="iconTemplate; context: { $implicit: this }"></ng-container>
2020
</div>
2121
<ng-container *ngIf="rowDraggable">

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

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
416416
super.ngAfterContentInit();
417417
}
418418

419+
/** @hidden */
420+
public featureColumnsWidth() {
421+
return super.featureColumnsWidth(this.headerHierarchyExpander);
422+
}
423+
419424
/**
420425
* @hidden
421426
*/
@@ -452,7 +457,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
452457
});
453458
this.columnList.reset(topCols);
454459
if (recalcColSizes && this.columnList.length !== colLength) {
455-
this.calculateGridSizes();
460+
this.calculateGridSizes(false);
456461
}
457462
}
458463
}
@@ -499,32 +504,6 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
499504
}
500505
}
501506

502-
/**
503-
* @hidden
504-
* Gets the combined width of the columns that are specific to the enabled grid features. They are fixed.
505-
* TODO: Remove for Angular 8. Calling parent class getter using super is not supported for now.
506-
*/
507-
public getFeatureColumnsWidth() {
508-
let width = super.getFeatureColumnsWidth();
509-
510-
if (this.hasExpandableChildren) {
511-
width += this.headerHierarchyExpander.nativeElement.offsetWidth || this.getDefaultExpanderWidth();
512-
}
513-
514-
return width;
515-
}
516-
517-
private getDefaultExpanderWidth(): number {
518-
switch (this.displayDensity) {
519-
case DisplayDensity.cosy:
520-
return 57;
521-
case DisplayDensity.compact:
522-
return 49;
523-
default:
524-
return 72;
525-
}
526-
}
527-
528507
/**
529508
* @hidden
530509
*/

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,14 @@ describe('IgxHierarchicalGrid Integration #hGrid', () => {
498498

499499
it('should render summaries for column inside a column group.', fakeAsync(/** row toggle rAF */() => {
500500
fixture.componentInstance.rowIsland.childColumns.first.hasSummary = false;
501+
tick();
501502
fixture.detectChanges();
502503
fixture.componentInstance.rowIsland.childColumns.last.hasSummary = true;
504+
tick();
503505
fixture.detectChanges();
504506

505507
(hierarchicalGrid.dataRowList.toArray()[0].nativeElement.children[0] as HTMLElement).click();
508+
tick();
506509
fixture.detectChanges();
507510

508511
const childGrids = fixture.debugElement.queryAll(By.css('igx-child-grid-row'));

0 commit comments

Comments
 (0)