Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
84183e9
fix(igxGrid): Grid should render all columns when grid width is set t…
Jul 12, 2019
cc8390e
chore(*): Fixing build.
Jul 12, 2019
d420613
Merge branch '7.2.x' into mkirova/fix-5288
mpavlinov Jul 17, 2019
98819da
chore(*): Handling null width inetgration with other grid features th…
Jul 18, 2019
ecb3490
Merge branch 'mkirova/fix-5288' of https://github.com/IgniteUI/ignite…
Jul 18, 2019
69fe21a
Merge branch '7.2.x' into mkirova/fix-5288
mpavlinov Jul 19, 2019
9edf57f
Merge branch '7.2.x' into mkirova/fix-5288
mpavlinov Jul 22, 2019
87754e9
chore(*): Additional handling for null width in combination with: hid…
Jul 25, 2019
a50b037
Merge branch 'mkirova/fix-5288' of https://github.com/IgniteUI/ignite…
Jul 25, 2019
cfdc275
chore(*): Use zone.run for interactions that change the width when ra…
Jul 25, 2019
25902a3
chore(*): If width is in % when grid width is null use min width.
Jul 26, 2019
0842e3e
Merge branch '7.2.x' into mkirova/fix-5288
ChronosSF Jul 31, 2019
ebb59c8
chore(*): In case width is null allow setting null for width host bin…
Jul 31, 2019
d934a35
Merge branch 'mkirova/fix-5288' of https://github.com/IgniteUI/ignite…
Jul 31, 2019
c684845
chore(*): Fixing issues with width = null.
Aug 1, 2019
0295f0a
chore(*): In case width is null, always apply minwidth to columns as …
Aug 1, 2019
3332aec
chore(*): Make check more specific to null.
Aug 1, 2019
8fa02ab
chore(*): Fixing merge issue.
Aug 1, 2019
3a9b597
chore(*): Fixing another test.
Aug 1, 2019
d3d9587
chore(*): DetectChanges before feature's column width is calculated s…
Aug 2, 2019
71ca342
Merge branch '7.2.x' into mkirova/fix-5288
kdinev Aug 5, 2019
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
87 changes: 80 additions & 7 deletions projects/igniteui-angular/src/lib/grids/grid-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
private _observer: MutationObserver;
protected _destroyed = false;
private overlayIDs = [];
private _hostWidth;
/**
* An accessor that sets the resource strings.
* By default it uses EN resources.
Expand Down Expand Up @@ -595,6 +596,13 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
}
}

/**
* @hidden
*/
@HostBinding('style.width')
get hostWidth() {
return this._width || this._hostWidth;
}
/**
* Returns the width of the `IgxGridComponent`.
* ```typescript
Expand All @@ -603,7 +611,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
* @memberof IgxGridBaseComponent
*/
@WatchChanges()
@HostBinding('style.width')
@Input()
public get width() {
return this._width;
Expand Down Expand Up @@ -2921,6 +2928,11 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
return this._unpinnedWidth;
}

get isHorizontalScrollHidden() {
const diff = this.unpinnedWidth - this.totalWidth;
return this.width === null || diff >= 0;
}

/**
* @hidden
*/
Expand Down Expand Up @@ -3849,7 +3861,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
*/
protected _derivePossibleWidth() {
if (!this._columnWidthSetByUser) {
this._columnWidth = this.getPossibleColumnWidth();
this._columnWidth = this.width !== null ? this.getPossibleColumnWidth() : MINIMUM_COLUMN_WIDTH + 'px';
this.columnList.forEach((column: IgxColumnComponent) => {
column.defaultWidth = this._columnWidth;
});
Expand Down Expand Up @@ -4042,20 +4054,39 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
}


if (!width) {
width = this.columnList.reduce((sum, item) => sum + parseInt((item.width || item.defaultWidth), 10), 0);
if (this.width === null || !width) {
width = this.getColumnWidthSum();
}

if (this.hasVerticalSroll()) {
if (this.hasVerticalSroll() && this.width !== null) {
width -= this.scrollWidth;
}
if (Number.isFinite(width) && width !== this.calcWidth) {
if ((Number.isFinite(width) || width === null) && width !== this.calcWidth) {
this.calcWidth = width;
this.cdr.detectChanges();
}
this._derivePossibleWidth();
}

private getColumnWidthSum(): number {
let colSum = 0;
const cols = this.visibleColumns
.filter(x => !x.columnGroup);
cols.forEach((item) => {
const isWidthInPercent = item.width && typeof item.width === 'string' && item.width.indexOf('%') !== -1;
if (isWidthInPercent) {
item.width = MINIMUM_COLUMN_WIDTH + 'px';
}
colSum += parseInt((item.width || item.defaultWidth), 10) || MINIMUM_COLUMN_WIDTH;
});
if (!colSum) {
return null;
}
this.cdr.detectChanges();
colSum += this.getFeatureColumnsWidth();
return colSum;
}

public hasVerticalSroll() {
if (!this._ngAfterViewInitPassed) { return false; }
const isScrollable = this.verticalScrollContainer.isScrollable();
Expand Down Expand Up @@ -4148,6 +4179,48 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
this.cdr.detectChanges();
this.resetCaches();
}

if (this.zone.isStable) {
this.zone.run(() => {
this._applyWidthHostBinding();
this.cdr.detectChanges();
});
} else {
this.zone.onStable.pipe(first()).subscribe(() => {
this.zone.run(() => {
this._applyWidthHostBinding();
});
});
}
}

private _applyWidthHostBinding() {
let width = this._width;
if (width === null) {
let currentWidth = this.calcWidth;
if (this.hasVerticalSroll()) {
currentWidth += this.scrollWidth;
}
width = currentWidth + 'px';
this.resetCaches();
}
this._hostWidth = width;
this.cdr.markForCheck();
}

/**
* @hidden
* Gets the combined width of the columns that are specific to the enabled grid features. They are fixed.
* Method used to override the calculations.
*/
public getFeatureColumnsWidth() {
let width = 0;

if (this.headerCheckboxContainer) {
width += this.headerCheckboxContainer.nativeElement.getBoundingClientRect().width;
}

return width;
}

/**
Expand Down Expand Up @@ -4182,7 +4255,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
protected getUnpinnedWidth(takeHidden = false) {
let width = this.isPercentWidth ?
this.calcWidth :
parseInt(this._width, 10);
parseInt(this.width, 10) || parseInt(this.hostWidth, 10) || this.calcWidth;
if (this.hasVerticalSroll() && !this.isPercentWidth) {
width -= this.scrollWidth;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3565,7 +3565,7 @@ describe('IgxGrid - Filtering actions - Excel style filtering', () => {
fix.detectChanges();

const headers: DebugElement[] = fix.debugElement.queryAll(By.directive(IgxGridHeaderGroupComponent));
const headerResArea = headers[2].children[0].nativeElement;
const headerResArea = headers[2].children[1].nativeElement;

const filterIcon = headerResArea.querySelector('.igx-excel-filter__icon');
filterIcon.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</div>

<div igxGridBody class="igx-grid__tbody">
<div class="igx-grid__tbody-content" role="rowgroup" (onDragStop)="selectionService.dragMode = $event" (onDragScroll)="dragScroll($event)" [igxGridDragSelect]="selectionService.dragMode" [style.height.px]='calcHeight' [style.width.px]='calcWidth + 1' #tbody (scroll)='scrollHandler($event)' (wheel)="wheelHandler()">
<div class="igx-grid__tbody-content" role="rowgroup" (onDragStop)="selectionService.dragMode = $event" (onDragScroll)="dragScroll($event)" [igxGridDragSelect]="selectionService.dragMode" [style.height.px]='calcHeight' [style.width.px]='calcWidth ? calcWidth + 1 : null' #tbody (scroll)='scrollHandler($event)' (wheel)="wheelHandler()">
<span *ngIf="hasMovableColumns && draggedColumn && pinnedColumns.length <= 0" [igxColumnMovingDrop]="parentVirtDir" [attr.droppable]="true" id="left" class="igx-grid__scroll-on-drag-left"></span>
<span *ngIf="hasMovableColumns && draggedColumn && pinnedColumns.length > 0" [igxColumnMovingDrop]="parentVirtDir" [attr.droppable]="true" id="left" class="igx-grid__scroll-on-drag-pinned" [style.left.px]="pinnedWidth"></span>
<ng-template igxGridFor let-rowData [igxGridForOf]="data
Expand Down Expand Up @@ -123,7 +123,7 @@
<div class="igx-grid__tfoot-thumb" [hidden]='!hasVerticalSroll()' [style.height.px]='summariesHeight' [style.width.px]="scrollWidth"></div>
</div>

<div class="igx-grid__scroll" [style.height]="'18px'" #scr [hidden]="unpinnedWidth - totalWidth >= 0">
<div class="igx-grid__scroll" [style.height]="'18px'" #scr [hidden]="isHorizontalScrollHidden">
<div class="igx-grid__scroll-start" [style.width.px]='pinnedWidth' [hidden]="pinnedWidth === 0"></div>
<div class="igx-grid__scroll-main" [style.width.px]='unpinnedWidth'>
<ng-template igxGridFor [igxGridForOf]='[]' #scrollContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,22 @@ describe('IgxGrid Component Tests', () => {
expect(virtDir.getSizeAt(2)).toEqual(150);

});

it('should render all columns if grid width is set to null.', async () => {
const fix = TestBed.createComponent(IgxGridDefaultRenderingComponent);
fix.componentInstance.initColumnsRows(5, 30);
const grid = fix.componentInstance.grid;
fix.detectChanges();

grid.width = null;
fix.detectChanges();
await wait(16);

// grid should render all columns and all should be visible.
const cells = grid.getRowByIndex(0).cells;
expect(cells.length).toBe(30);
expect(parseInt(grid.hostWidth, 10)).toBe(30 * 136);
});
});

describe('IgxGrid - API methods', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<div class="igx-grid__tfoot-thumb" [hidden]='!hasVerticalSroll()' [style.height.px]='summariesHeight' [style.width.px]="scrollWidth"></div>
</div>

<div class="igx-grid__scroll" [style.height]="'18px'" #scr [hidden]="unpinnedWidth - totalWidth >= 0">
<div class="igx-grid__scroll" [style.height]="'18px'" #scr [hidden]="isHorizontalScrollHidden">
<div class="igx-grid__scroll-start" [style.width.px]='pinnedWidth' [hidden]="pinnedWidth === 0"></div>
<div class="igx-grid__scroll-main" [style.width.px]='unpinnedWidth'>
<ng-template igxGridFor [igxGridForOf]='[]' #scrollContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,19 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseCompone
return width;
}

/**
* @hidden
* Gets the combined width of the columns that are specific to the enabled grid features. They are fixed.
* Method used to override the calculations.
*/
public getFeatureColumnsWidth() {
let width = super.getFeatureColumnsWidth();
if (this.hasExpandableChildren) {
width += this.headerHierarchyExpander.nativeElement.clientWidth || this.getDefaultExpanderWidth();
}
return width;
}

private getDefaultExpanderWidth(): number {
switch (this.displayDensity) {
case DisplayDensity.cosy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<div class="igx-grid__tfoot-thumb" [hidden]='!hasVerticalSroll()' [style.height.px]='summariesHeight' [style.width.px]="scrollWidth"></div>
</div>

<div class="igx-grid__scroll" [style.height]="'18px'" #scr [hidden]="unpinnedWidth - totalWidth >= 0">
<div class="igx-grid__scroll" [style.height]="'18px'" #scr [hidden]="isHorizontalScrollHidden">
<div class="igx-grid__scroll-start" [style.width.px]='pinnedWidth' [hidden]="pinnedWidth === 0"></div>
<div class="igx-grid__scroll-main" [style.width.px]='unpinnedWidth'>
<ng-template igxGridFor [igxGridForOf]='[]' #scrollContainer>
Expand Down