Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0d60ec8
fix(igxGrid): Grid should render all columns when grid width is set t…
Jul 12, 2019
667e7e0
chore(*): Fixing build.
Jul 12, 2019
951c0b6
chore(*): Merge from 8.0.x.
Jul 12, 2019
efb9fdc
chore(*): Handling null width inetgration with other grid features th…
Jul 18, 2019
6a8d964
Merge branch '8.0.x' into mkirova/fix-5288-8.0.x
MayaKirova Jul 18, 2019
fb2ee81
chore(*): In case withd is null make sure scroll width is not taken i…
Jul 18, 2019
a1ac9ef
chore(*): Include feature's column width to calculated body width whe…
Jul 19, 2019
909f76f
Merge branch '8.0.x' into mkirova/fix-5288-8.0.x
kdinev Jul 23, 2019
6242755
chore(*): Additional handling for null width in combination with: hid…
Jul 25, 2019
d874727
chore(*): Use zone.run for interactions that change the width when ra…
Jul 25, 2019
26e59bc
chore(*): Adding support for null width + mrl. Fixing getPossibleColu…
Jul 26, 2019
fe3c122
chore(*): If width is in % when grid width is null use min width.
Jul 26, 2019
c24d410
Merge branch '8.0.x' into mkirova/fix-5288-8.0.x
ChronosSF Jul 31, 2019
c900da0
chore(*): In case width is null allow setting null for width host bin…
Jul 31, 2019
1a7fbb7
Merge branch 'mkirova/fix-5288-8.0.x' of https://github.com/IgniteUI/…
Jul 31, 2019
0d1d605
chore(*): Fixing issues with width = null.
Aug 1, 2019
c520ce0
chore(*): In case width is null, always apply minwidth to columns as …
Aug 1, 2019
b5b8bfd
chore(*): Make check more specific to null.
Aug 1, 2019
9a5539d
chore(*): Fixing another test.
Aug 1, 2019
0a1fae1
chore(*): DetectChanges before feature's column width is calculated s…
Aug 2, 2019
fb42df7
Merge branch '8.0.x' into mkirova/fix-5288-8.0.x
ChronosSF Aug 2, 2019
44216f4
Merge branch '8.0.x' into mkirova/fix-5288-8.0.x
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
76 changes: 66 additions & 10 deletions projects/igniteui-angular/src/lib/grids/grid-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,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 @@ -648,6 +649,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 @@ -656,7 +664,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
* @memberof IgxGridBaseComponent
*/
@WatchChanges()
@HostBinding('style.width')
@Input()
get width() {
return this._width;
Expand Down Expand Up @@ -3058,6 +3065,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
* Gets the combined width of the columns that are specific to the enabled grid features. They are fixed.
Expand Down Expand Up @@ -4020,7 +4032,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) => {
if (this.hasColumnLayouts && parseInt(this._columnWidth, 10)) {
const columnWidthCombined = parseInt(this._columnWidth, 10) * (column.colEnd ? column.colEnd - column.colStart : 1);
Expand Down Expand Up @@ -4175,9 +4187,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
parseInt(this.document.defaultView.getComputedStyle(this.nativeElement).getPropertyValue('width'), 10);
}

if (this.showRowCheckboxes) {
computedWidth -= this.headerCheckboxContainer ? this.headerCheckboxContainer.nativeElement.offsetWidth : 0;
}
computedWidth -= this.getFeatureColumnsWidth();

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

Expand Down Expand Up @@ -4237,20 +4247,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.hasColumnLayouts ?
this.visibleColumns.filter(x => x.columnLayout) : 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 @@ -4342,6 +4371,33 @@ 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();
}

/**
Expand Down Expand Up @@ -4392,7 +4448,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 @@ -3509,7 +3509,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 @@ -129,7 +129,7 @@
<div igxGridBody (keydown.control.c)="copyHandlerIE()" (copy)="copyHandler($event)" 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)'
[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"
Expand Down Expand Up @@ -190,7 +190,7 @@
[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 @@ -1383,6 +1383,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 @@ -213,6 +213,7 @@ describe('IgxGrid - Row Drag Tests', () => {
}));
it('should align horizontal scrollbar with first column when column pinning is disabled', fakeAsync(() => {
// has no draggable and selectable rows
grid.width = '400px';
grid.rowSelectable = false;
grid.rowDraggable = false;
tick();
Expand Down Expand Up @@ -248,6 +249,7 @@ describe('IgxGrid - Row Drag Tests', () => {
expect(rowSelectRect.right).toBe(horizontalScrollbarRect.left);
}));
it('should align horizontal scrollbar with first non-pinned column when column pinning is enabled', fakeAsync(() => {
grid.width = '400px';
grid.pinColumn('ProductName');
tick();
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
[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 @@ -519,7 +519,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseCompone
return width;
}

private getDefaultExpanderWidth(): number {
private getDefaultExpanderWidth(): number {
switch (this.displayDensity) {
case DisplayDensity.cosy:
return 57;
Expand Down Expand Up @@ -710,16 +710,6 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseCompone
}
}

/**
* @hidden
*/
public getPossibleColumnWidth() {
let computedWidth = this.calcWidth || parseInt(
this.document.defaultView.getComputedStyle(this.nativeElement).getPropertyValue('width'), 10);
computedWidth -= this.headerHierarchyExpander.nativeElement.clientWidth;
return super.getPossibleColumnWidth(computedWidth);
}

protected getChildGrids(inDeph?: boolean) {
return this.hgridAPI.getChildGrids(inDeph);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
[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