Skip to content

Commit fc62814

Browse files
Merge branch '18.2.x' into mkirkova-fix-15113-18.2.x
2 parents 60b0eb9 + d67b13c commit fc62814

File tree

9 files changed

+84
-13
lines changed

9 files changed

+84
-13
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,9 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
25272527
const colWidth = this.width;
25282528
const isPercentageWidth = colWidth && typeof colWidth === 'string' && colWidth.indexOf('%') !== -1;
25292529
const isAutoWidth = colWidth && typeof colWidth === 'string' && colWidth === 'fit-content';
2530-
if (isPercentageWidth) {
2530+
if (isPercentageWidth && this.grid.isColumnWidthSum) {
2531+
this._calcWidth = this.grid.minColumnWidth;
2532+
} else if (isPercentageWidth ) {
25312533
this._calcWidth = Math.floor(parseFloat(colWidth) / 100 * this.grid.calcWidth);
25322534
} else if (!colWidth || isAutoWidth && !this.autoSize) {
25332535
// no width

projects/igniteui-angular/src/lib/grids/common/grid.interface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,10 @@ export interface GridType extends IGridDataBindable {
718718
isLoading: boolean;
719719
/** @hidden @internal */
720720
gridSize: Size;
721-
721+
/** @hidden @internal */
722+
isColumnWidthSum: boolean;
723+
/** @hidden @internal */
724+
minColumnWidth: number;
722725
/** Strategy, used for cloning the provided data. The type has one method, that takes any type of data */
723726
dataCloneStrategy: IDataCloneStrategy;
724727

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,6 +3001,12 @@ export abstract class IgxGridBaseDirective implements GridType,
30013001
* @hidden @internal
30023002
*/
30033003
public filteringPipeTrigger = 0;
3004+
3005+
/**
3006+
* @hidden @internal
3007+
*/
3008+
public isColumnWidthSum = false;
3009+
30043010
/**
30053011
* @hidden @internal
30063012
*/
@@ -3201,7 +3207,7 @@ export abstract class IgxGridBaseDirective implements GridType,
32013207
private _columnSelectionMode: GridSelectionMode = GridSelectionMode.none;
32023208

32033209
private lastAddedRowIndex;
3204-
protected isColumnWidthSum = false;
3210+
32053211
private _currencyPositionLeft: boolean;
32063212

32073213
private rowEditPositioningStrategy = new RowEditPositionStrategy({
@@ -3234,7 +3240,7 @@ export abstract class IgxGridBaseDirective implements GridType,
32343240
/**
32353241
* @hidden @internal
32363242
*/
3237-
protected get minColumnWidth() {
3243+
public get minColumnWidth() {
32383244
return MINIMUM_COLUMN_WIDTH;
32393245
}
32403246

@@ -6488,8 +6494,10 @@ export abstract class IgxGridBaseDirective implements GridType,
64886494

64896495

64906496
if (this.width === null || !width) {
6491-
width = this.getColumnWidthSum();
64926497
this.isColumnWidthSum = true;
6498+
width = this.getColumnWidthSum();
6499+
} else {
6500+
this.isColumnWidthSum = false;
64936501
}
64946502

64956503
if (this.hasVerticalScroll() && this.width !== null) {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { IgxAvatarComponent } from '../../avatar/avatar.component';
1616
import { IColumnResizeEventArgs, IgxColumnComponent } from '../public_api';
1717
import { Size } from "../common/enums";
1818
import { setElementSize } from '../../test-utils/helper-utils.spec';
19+
import { IgxColumnResizerDirective } from '../resizing/resizer.directive';
1920

2021
describe('IgxGrid - Deferred Column Resizing #grid', () => {
2122

@@ -133,6 +134,27 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
133134
expect(grid.columnList.get(1).width).toEqual('70px');
134135
}));
135136

137+
it('should calculate correctly resizer position and column width when grid is scaled and zoomed', fakeAsync(() => {
138+
grid.nativeElement.style.transform = 'scale(1.2)';
139+
grid.nativeElement.style.setProperty('zoom', '1.05');
140+
fixture.detectChanges();
141+
headerResArea = GridFunctions.getHeaderResizeArea(headers[1]).nativeElement;
142+
UIInteractions.simulateMouseEvent('mousedown', headerResArea, 153, 0);
143+
tick(200);
144+
fixture.detectChanges();
145+
146+
const resizer = GridFunctions.getResizer(fixture);
147+
const resizerDirective = resizer.componentInstance.resizer as IgxColumnResizerDirective;
148+
const leftSetterSpy = spyOnProperty(resizerDirective, 'left', 'set').and.callThrough();
149+
UIInteractions.simulateMouseEvent('mousemove', resizer.nativeElement, 200, 5);
150+
UIInteractions.simulateMouseEvent('mouseup', resizer.nativeElement, 200, 5);
151+
fixture.detectChanges();
152+
153+
expect(leftSetterSpy).toHaveBeenCalled();
154+
expect(parseInt(leftSetterSpy.calls.mostRecent().args[0].toFixed(0))).toEqual(200);
155+
expect(parseInt(grid.columnList.get(1).headerCell.nativeElement.getBoundingClientRect().width.toFixed(0))).toEqual(173);
156+
}));
157+
136158
it('should be able to resize column to the minWidth < defaultMinWidth', fakeAsync(() => {
137159
const column = grid.getColumnByName('ID');
138160
column.minWidth = 'a';

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,21 @@ describe('IgxGrid Component Tests #grid', () => {
18701870
expect(parseInt(grid.hostWidth, 10)).toBe(30 * 136);
18711871
});
18721872

1873+
it('should render grid and columns with correct width when all are in % and inside a hidden container.', () => {
1874+
// in this case since the grid width is 0, the grid will use the sum of the columns
1875+
// those should resolve to 136px, as per the docs
1876+
const fix = TestBed.createComponent(IgxGridColumnHiddenPercentageWidthComponent);
1877+
const grid = fix.componentInstance.grid;
1878+
grid.width = '100%';
1879+
// 4 cols - 10% width
1880+
fix.componentInstance.initColumnsRows(5, 4);
1881+
fix.detectChanges();
1882+
1883+
expect(grid.calcWidth).toBe(136*4);
1884+
expect(grid.columns[0].calcWidth).toBe(136);
1885+
expect(grid.columns[1].calcWidth).toBe(136);
1886+
});
1887+
18731888
it('should retain column with in % after hiding/showing grid with 100% width', () => {
18741889
const fix = TestBed.createComponent(IgxGridColumnPercentageWidthComponent);
18751890
fix.componentInstance.initColumnsRows(5, 3);
@@ -3100,6 +3115,18 @@ export class IgxGridColumnPercentageWidthComponent extends IgxGridDefaultRenderi
31003115
}
31013116
}
31023117

3118+
@Component({
3119+
template: `<igx-grid #grid [hidden]="hidden" [data]="data" [autoGenerate]="false">
3120+
<igx-column *ngFor="let col of columns" [width]="'10%'" [field]="col.key" [header]="col.key" [dataType]="col.dataType">
3121+
</igx-column>
3122+
</igx-grid>`,
3123+
standalone: true,
3124+
imports: [IgxGridComponent, IgxColumnComponent, NgFor]
3125+
})
3126+
export class IgxGridColumnHiddenPercentageWidthComponent extends IgxGridDefaultRenderingComponent {
3127+
public hidden = true;
3128+
}
3129+
31033130
@Component({
31043131
template: `<div>
31053132
<igx-grid #grid [data]="data" height='300px' [style.--ig-size]="1" [autoGenerate]="true"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
479479
/**
480480
* @hidden @internal
481481
*/
482-
protected override get minColumnWidth() {
482+
public override get minColumnWidth() {
483483
if (this.superCompactMode) {
484484
return MINIMUM_COLUMN_WIDTH_SUPER_COMPACT;
485485
} else {

projects/igniteui-angular/src/lib/grids/resizing/resizer.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
[restrictHResizeMax]="colResizingService.restrictResizeMax"
55
[restrictHResizeMin]="colResizingService.restrictResizeMin"
66
[restrictResizerTop]="restrictResizerTop"
7-
(resizeEnd)="colResizingService.resizeColumn($event)">
7+
(resizeEnd)="colResizingService.resizeColumn($event, resizer.ratio)">
88
</div>

projects/igniteui-angular/src/lib/grids/resizing/resizer.directive.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ export class IgxColumnResizerDirective implements OnInit, OnDestroy {
4141
@Output() public resize = new Subject<any>();
4242

4343
private _left: number;
44+
private _ratio: number = 1;
4445
private _destroy = new Subject<boolean>();
4546

47+
public get ratio(): number {
48+
return this._ratio;
49+
}
50+
4651
constructor(
4752
public element: ElementRef<HTMLElement>,
4853
@Inject(DOCUMENT) public document,
@@ -56,7 +61,7 @@ export class IgxColumnResizerDirective implements OnInit, OnDestroy {
5661
.pipe(
5762
takeUntil(this._destroy),
5863
takeUntil<MouseEvent>(this.resizeEnd),
59-
map((event) => event.clientX - offset),
64+
map((event) => (event.clientX - offset) / (this._ratio)),
6065
))
6166
)
6267
.subscribe((pos) => {
@@ -113,8 +118,12 @@ export class IgxColumnResizerDirective implements OnInit, OnDestroy {
113118
public onMousedown(event: MouseEvent) {
114119
event.preventDefault();
115120
const parent = this.element.nativeElement.parentElement.parentElement;
116-
117-
this.left = this._left = event.clientX - parent.getBoundingClientRect().left;
121+
const parentRectWidth = parent.getBoundingClientRect().width;
122+
const parentComputedWidth = parseFloat(window.getComputedStyle(parent).width);
123+
if (Math.abs(parentRectWidth - parentComputedWidth) > 1) {
124+
this._ratio = parentRectWidth / parentComputedWidth;
125+
}
126+
this.left = this._left = (event.clientX - parent.getBoundingClientRect().left) / this._ratio;
118127
this.top = (event.target as HTMLElement).getBoundingClientRect().top - parent.getBoundingClientRect().top;
119128

120129
this.resizeStart.next(event);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class IgxColumnResizingService {
3535
* @hidden
3636
*/
3737
public getColumnHeaderRenderedWidth() {
38-
return this.column.headerCell.nativeElement.getBoundingClientRect().width;
38+
return parseFloat(window.getComputedStyle(this.column.headerCell.nativeElement).width);
3939
}
4040

4141
/**
@@ -101,9 +101,9 @@ export class IgxColumnResizingService {
101101
/**
102102
* Resizes the column regaridng to the column minWidth and maxWidth.
103103
*/
104-
public resizeColumn(event: MouseEvent) {
104+
public resizeColumn(event: MouseEvent, ratio: number = 1) {
105105
this.showResizer = false;
106-
const diff = event.clientX - this.startResizePos;
106+
const diff = (event.clientX - this.startResizePos) / ratio;
107107

108108
const colWidth = this.column.width;
109109
const isPercentageWidth = colWidth && typeof colWidth === 'string' && colWidth.indexOf('%') !== -1;

0 commit comments

Comments
 (0)