Skip to content

Commit 41bd868

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Fix tests.
1 parent c120308 commit 41bd868

File tree

3 files changed

+44
-26
lines changed

3 files changed

+44
-26
lines changed

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -440,24 +440,36 @@ export class IgxColumnComponent implements AfterContentInit {
440440
@Input()
441441
public maxWidth: string;
442442

443+
/**
444+
* @hidden
445+
*/
443446
get maxWidthPx() {
444447
const gridAvailableSize = this.grid.calcWidth;
445448
const isPercentageWidth = this.maxWidth && typeof this.maxWidth === 'string' && this.maxWidth.indexOf('%') !== -1;
446449
return isPercentageWidth ? parseFloat(this.maxWidth) / 100 * gridAvailableSize : parseFloat(this.maxWidth);
447450
}
448451

452+
/**
453+
* @hidden
454+
*/
449455
get maxWidthPercent() {
450456
const gridAvailableSize = this.grid.calcWidth;
451457
const isPercentageWidth = this.maxWidth && typeof this.maxWidth === 'string' && this.maxWidth.indexOf('%') !== -1;
452458
return isPercentageWidth ? parseFloat(this.maxWidth) : parseFloat(this.maxWidth) / gridAvailableSize * 100;
453459
}
454460

461+
/**
462+
* @hidden
463+
*/
455464
get minWidthPx() {
456465
const gridAvailableSize = this.grid.calcWidth;
457466
const isPercentageWidth = this.minWidth && typeof this.minWidth === 'string' && this.minWidth.indexOf('%') !== -1;
458467
return isPercentageWidth ? parseFloat(this.minWidth) / 100 * gridAvailableSize : parseFloat(this.minWidth);
459468
}
460469

470+
/**
471+
* @hidden
472+
*/
461473
get minWidthPercent() {
462474
const gridAvailableSize = this.grid.calcWidth;
463475
const isPercentageWidth = this.minWidth && typeof this.minWidth === 'string' && this.minWidth.indexOf('%') !== -1;
@@ -1779,27 +1791,29 @@ export class IgxColumnComponent implements AfterContentInit {
17791791
*/
17801792
public autosize() {
17811793
if (!this.columnGroup) {
1782-
const size = this.getLargestCellWidth();
1783-
const gridAvailableSize = this.grid.calcWidth;
1784-
let newWidth;
1785-
const isPercentageWidth = this.width && typeof this.width === 'string' && this.width.indexOf('%') !== -1;
1786-
if (isPercentageWidth) {
1787-
const percentageSize = parseFloat(size) / gridAvailableSize * 100;
1788-
newWidth = percentageSize + '%';
1789-
} else {
1790-
newWidth = size;
1791-
}
1792-
if (this.maxWidth && (parseFloat(size) > this.maxWidthPx)) {
1793-
newWidth = isPercentageWidth ? this.maxWidthPercent + '%' : this.maxWidthPx + 'px';
1794-
} else if (parseFloat(size) < this.minWidthPx) {
1795-
newWidth = isPercentageWidth ? this.minWidthPercent + '%' : this.minWidthPx + 'px';
1796-
}
1797-
1798-
this.width = newWidth;
1794+
const size = this.getAutoSize();
1795+
this.width = size;
17991796
this.grid.reflow();
18001797
}
18011798
}
18021799

1800+
/**
1801+
* @hidden
1802+
*/
1803+
public getAutoSize() {
1804+
const size = this.getLargestCellWidth();
1805+
const gridAvailableSize = this.grid.calcWidth;
1806+
let newWidth;
1807+
const isPercentageWidth = this.width && typeof this.width === 'string' && this.width.indexOf('%') !== -1;
1808+
if (isPercentageWidth) {
1809+
const percentageSize = parseFloat(size) / gridAvailableSize * 100;
1810+
newWidth = percentageSize + '%';
1811+
} else {
1812+
newWidth = size;
1813+
}
1814+
return newWidth;
1815+
}
1816+
18031817
/**
18041818
* @hidden
18051819
*/
@@ -1905,7 +1919,7 @@ export class IgxColumnComponent implements AfterContentInit {
19051919
const colWidth = this.width;
19061920
const isPercentageWidth = colWidth && typeof colWidth === 'string' && colWidth.indexOf('%') !== -1;
19071921
if (isPercentageWidth) {
1908-
this._calcWidth = parseInt(colWidth, 10) / 100 * grid.calcWidth;
1922+
this._calcWidth = parseInt(colWidth, 10) / 100 * (grid.calcWidth - grid.featureColumnsWidth());
19091923
} else if (!colWidth) {
19101924
// no width
19111925
this._calcWidth = this.defaultWidth || grid.getPossibleColumnWidth();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
392392
UIInteractions.simulateMouseEvent('mouseup', resizer, 350, 5);
393393
fixture.detectChanges();
394394

395-
expect(grid.columns[1].width).toEqual('250px');
395+
// column has maxWidth='150px'
396+
expect(grid.columns[1].width).toEqual('150px');
396397
});
397398

398399
it('should autoresize column on double click.', async() => {
@@ -490,7 +491,7 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
490491
expect(grid.columns[0].width).toEqual('300px');
491492
expect(fixture.componentInstance.count).toEqual(1);
492493
expect(fixture.componentInstance.column).toBe(grid.columns[0]);
493-
expect(fixture.componentInstance.prevWidth).toEqual('150');
494+
expect(fixture.componentInstance.prevWidth).toEqual('150px');
494495
expect(fixture.componentInstance.newWidth).toEqual('300px');
495496

496497
expect(grid.columns[1].width).toEqual('150px');

projects/igniteui-angular/src/lib/grids/resizing/resizing.service.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,17 @@ export class IgxColumnResizingService {
7777
* Autosizes the column to the longest currently visible cell value, including the header cell.
7878
* If the column has a predifined maxWidth and the autosized column width will become bigger than it,
7979
* then the column is sized to its maxWidth.
80-
* If the column is pinned and the autosized column width will cause the pinned area to become bigger
81-
* than the maximum allowed pinned area width (80% of the total grid width), autosizing will be deismissed.
8280
*/
8381
public autosizeColumnOnDblClick() {
8482
const currentColWidth = this.column.headerCell.elementRef.nativeElement.getBoundingClientRect().width;
85-
86-
87-
this.column.autosize();
83+
const isPercentageWidth = this.column.width && typeof this.column.width === 'string' && this.column.width.indexOf('%') !== -1;
84+
let size = this.column.getAutoSize();
85+
if (this.column.maxWidth && (parseFloat(size) > this.column.maxWidthPx)) {
86+
size = isPercentageWidth ? this.column.maxWidthPercent + '%' : this.column.maxWidthPx + 'px';
87+
} else if (parseFloat(size) < this.column.minWidthPx) {
88+
size = isPercentageWidth ? this.column.minWidthPercent + '%' : this.column.minWidthPx + 'px';
89+
}
90+
this.column.width = size;
8891

8992
this.zone.run(() => {});
9093

@@ -106,7 +109,7 @@ export class IgxColumnResizingService {
106109
const isPercentageWidth = colWidth && typeof colWidth === 'string' && colWidth.indexOf('%') !== -1;
107110
let currentColWidth = parseFloat(colWidth);
108111
const actualWidth = this.column.headerCell.elementRef.nativeElement.getBoundingClientRect().width;
109-
currentColWidth = Number.isNaN(currentColWidth) ? actualWidth : currentColWidth + 'px';
112+
currentColWidth = Number.isNaN(currentColWidth) ? parseFloat(actualWidth) : currentColWidth;
110113

111114
if (isPercentageWidth) {
112115
this._handlePercentageResize(diff, this.column);

0 commit comments

Comments
 (0)