Skip to content

Commit 5b9c82d

Browse files
authored
fix(Grid): Add better handling for fraction numbers, as result of zoom. (#16427)
1 parent c0c3dd2 commit 5b9c82d

4 files changed

Lines changed: 44 additions & 41 deletions

File tree

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
423423
}
424424

425425
public isScrollable() {
426-
return this.scrollComponent.size > parseInt(this.igxForContainerSize, 10);
426+
return this.scrollComponent.size > parseFloat(this.igxForContainerSize);
427427
}
428428

429429
/**
@@ -556,8 +556,8 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
556556
}
557557
const containerSize = 'igxForContainerSize';
558558
if (containerSize in changes && !changes[containerSize].firstChange && this.igxForOf) {
559-
const prevSize = parseInt(changes[containerSize].previousValue, 10);
560-
const newSize = parseInt(changes[containerSize].currentValue, 10);
559+
const prevSize = parseFloat(changes[containerSize].previousValue);
560+
const newSize = parseFloat(changes[containerSize].currentValue);
561561
this._recalcOnContainerChange({prevSize, newSize});
562562
}
563563
}
@@ -614,7 +614,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
614614
return false;
615615
}
616616
const originalVirtScrollTop = this._virtScrollPosition;
617-
const containerSize = parseInt(this.igxForContainerSize, 10);
617+
const containerSize = parseFloat(this.igxForContainerSize);
618618
const maxVirtScrollTop = this._virtSize - containerSize;
619619

620620
this._bScrollInternal = true;
@@ -627,7 +627,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
627627
if (Math.abs(add / this._virtRatio) < 1) {
628628
// Actual scroll delta that was added is smaller than 1 and onScroll handler doesn't trigger when scrolling < 1px
629629
const scrollOffset = this.fixedUpdateAllElements(this._virtScrollPosition);
630-
// scrollOffset = scrollOffset !== parseInt(this.igxForItemSize, 10) ? scrollOffset : 0;
630+
// scrollOffset = scrollOffset !== parseFloat(this.igxForItemSize, 10) ? scrollOffset : 0;
631631
this.dc.instance._viewContainer.element.nativeElement.style.top = -(scrollOffset) + 'px';
632632
}
633633

@@ -659,7 +659,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
659659
if (index < 0 || index > (this.isRemote ? this.totalItemCount : this.igxForOf.length) - 1) {
660660
return;
661661
}
662-
const containerSize = parseInt(this.igxForContainerSize, 10);
662+
const containerSize = parseFloat(this.igxForContainerSize);
663663
const isPrevItem = index < this.state.startIndex || this.scrollPosition > this.sizesCache[index];
664664
let nextScroll = isPrevItem ? this.sizesCache[index] : this.sizesCache[index + 1] - containerSize;
665665
if (nextScroll < 0) {
@@ -684,7 +684,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
684684
*/
685685
public scrollNext() {
686686
const scr = Math.abs(Math.ceil(this.scrollPosition));
687-
const endIndex = this.getIndexAt(scr + parseInt(this.igxForContainerSize, 10), this.sizesCache);
687+
const endIndex = this.getIndexAt(scr + parseFloat(this.igxForContainerSize), this.sizesCache);
688688
this.scrollTo(endIndex);
689689
}
690690

@@ -707,7 +707,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
707707
* ```
708708
*/
709709
public scrollNextPage() {
710-
this.addScroll(parseInt(this.igxForContainerSize, 10));
710+
this.addScroll(parseFloat(this.igxForContainerSize));
711711
}
712712

713713
/**
@@ -718,7 +718,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
718718
* ```
719719
*/
720720
public scrollPrevPage() {
721-
const containerSize = (parseInt(this.igxForContainerSize, 10));
721+
const containerSize = (parseFloat(this.igxForContainerSize));
722722
this.addScroll(-containerSize);
723723
}
724724

@@ -741,7 +741,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
741741
// fisrt item is not fully in view
742742
startIndex++;
743743
}
744-
const endIndex = this.getIndexAt(this.scrollPosition + parseInt(this.igxForContainerSize, 10), this.sizesCache);
744+
const endIndex = this.getIndexAt(this.scrollPosition + parseFloat(this.igxForContainerSize), this.sizesCache);
745745
return endIndex - startIndex;
746746
}
747747

@@ -780,7 +780,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
780780
* ```
781781
*/
782782
public getScrollForIndex(index: number, bottom?: boolean) {
783-
const containerSize = parseInt(this.igxForContainerSize, 10);
783+
const containerSize = parseFloat(this.igxForContainerSize);
784784
const scroll = bottom ? Math.max(0, this.sizesCache[index + 1] - containerSize) : this.sizesCache[index];
785785
return scroll;
786786
}
@@ -805,7 +805,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
805805
this._embeddedViews.map(view =>
806806
view.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE) || view.rootNodes[0].nextElementSibling)[index - this.state.startIndex] : null;
807807
const rowHeight = this.getSizeAt(index);
808-
const containerSize = parseInt(this.igxForContainerSize, 10);
808+
const containerSize = parseFloat(this.igxForContainerSize);
809809
const containerOffset = -(this.scrollPosition - this.sizesCache[this.state.startIndex]);
810810
const endTopOffset = targetNode ? targetNode.offsetTop + rowHeight + containerOffset : containerSize + rowHeight;
811811
return !targetNode || targetNode.offsetTop < Math.abs(containerOffset)
@@ -828,7 +828,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
828828
const rNode = rNodes[i];
829829
if (rNode) {
830830
const height = window.getComputedStyle(rNode).getPropertyValue('height');
831-
const h = parseFloat(height) || parseInt(this.igxForItemSize, 10);
831+
const h = parseFloat(height) || parseFloat(this.igxForItemSize);
832832
const index = this.state.startIndex + i;
833833
if (!this.isRemote && !this.igxForOf[index]) {
834834
continue;
@@ -863,7 +863,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
863863
}
864864
const scrToBottom = this._isScrolledToBottom && !this.dc.instance.notVirtual;
865865
if (scrToBottom && !this._isAtBottomIndex) {
866-
const containerSize = parseInt(this.igxForContainerSize, 10);
866+
const containerSize = parseFloat(this.igxForContainerSize);
867867
const maxVirtScrollTop = this._virtSize - containerSize;
868868
this._bScrollInternal = true;
869869
this._virtScrollPosition = maxVirtScrollTop;
@@ -912,7 +912,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
912912
*/
913913
protected onScroll(event) {
914914
/* in certain situations this may be called when no scrollbar is visible */
915-
if (!parseInt(this.scrollComponent.nativeElement.style.height, 10)) {
915+
if (!parseFloat(this.scrollComponent.nativeElement.style.height)) {
916916
return;
917917
}
918918
if (!this._bScrollInternal) {
@@ -1100,7 +1100,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
11001100
protected onHScroll(event) {
11011101
/* in certain situations this may be called when no scrollbar is visible */
11021102
const firstScrollChild = this.scrollComponent.nativeElement.children.item(0) as HTMLElement;
1103-
if (!parseInt(firstScrollChild.style.width, 10)) {
1103+
if (!parseFloat(firstScrollChild.style.width)) {
11041104
return;
11051105
}
11061106
if (!this._bScrollInternal) {
@@ -1272,7 +1272,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
12721272
let maxLength = 0;
12731273
const arr = [];
12741274
let sum = 0;
1275-
const availableSize = parseInt(this.igxForContainerSize, 10);
1275+
const availableSize = parseFloat(this.igxForContainerSize);
12761276
if (!availableSize) {
12771277
return 0;
12781278
}
@@ -1302,7 +1302,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
13021302
const prevItem = this.igxForOf[prevIndex];
13031303
const prevSize = dimension === 'height' ?
13041304
this.individualSizeCache[prevIndex] :
1305-
parseInt(prevItem[dimension], 10);
1305+
parseFloat(prevItem[dimension]);
13061306
sum = arr.reduce(reducer, prevSize);
13071307
arr.unshift(prevItem);
13081308
length = arr.length;
@@ -1349,19 +1349,19 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
13491349
this.dc.instance.notVirtual = !(this.igxForContainerSize && this.dc && this.state.chunkSize < count);
13501350
const scrollable = containerSizeInfo ? this.scrollComponent.size > containerSizeInfo.prevSize : this.isScrollable();
13511351
if (this.igxForScrollOrientation === 'horizontal') {
1352-
const totalWidth = parseInt(this.igxForContainerSize, 10) > 0 ? this._calcSize() : 0;
1353-
if (totalWidth <= parseInt(this.igxForContainerSize, 10)) {
1352+
const totalWidth = parseFloat(this.igxForContainerSize) > 0 ? this._calcSize() : 0;
1353+
if (totalWidth <= parseFloat(this.igxForContainerSize)) {
13541354
this.resetScrollPosition();
13551355
}
13561356
this.scrollComponent.nativeElement.style.width = this.igxForContainerSize + 'px';
13571357
this.scrollComponent.size = totalWidth;
13581358
}
13591359
if (this.igxForScrollOrientation === 'vertical') {
13601360
const totalHeight = this._calcSize();
1361-
if (totalHeight <= parseInt(this.igxForContainerSize, 10)) {
1361+
if (totalHeight <= parseFloat(this.igxForContainerSize)) {
13621362
this.resetScrollPosition();
13631363
}
1364-
this.scrollComponent.nativeElement.style.height = parseInt(this.igxForContainerSize, 10) + 'px';
1364+
this.scrollComponent.nativeElement.style.height = parseFloat(this.igxForContainerSize) + 'px';
13651365
this.scrollComponent.size = totalHeight;
13661366
}
13671367
if (scrollable !== this.isScrollable()) {
@@ -1453,7 +1453,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
14531453
}
14541454

14551455
protected _calcVirtualScrollPosition(scrollPosition: number) {
1456-
const containerSize = parseInt(this.igxForContainerSize, 10);
1456+
const containerSize = parseFloat(this.igxForContainerSize);
14571457
const maxRealScrollPosition = this.scrollComponent.size - containerSize;
14581458
const realPercentScrolled = maxRealScrollPosition !== 0 ? scrollPosition / maxRealScrollPosition : 0;
14591459
const maxVirtScroll = this._virtSize - containerSize;
@@ -1462,7 +1462,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
14621462

14631463
protected _getItemSize(item, dimension: string): number {
14641464
const dim = item ? item[dimension] : null;
1465-
return typeof dim === 'number' ? dim : parseInt(this.igxForItemSize, 10) || 0;
1465+
return typeof dim === 'number' ? dim : parseFloat(this.igxForItemSize) || 0;
14661466
}
14671467

14681468
protected _updateScrollOffset() {
@@ -1485,8 +1485,8 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
14851485
if (Math.abs(sizeDiff) > 0 && this.scrollPosition > 0) {
14861486
this.recalcUpdateSizes();
14871487
const offset = this.igxForScrollOrientation === 'horizontal' ?
1488-
parseInt(this.dc.instance._viewContainer.element.nativeElement.style.left, 10) :
1489-
parseInt(this.dc.instance._viewContainer.element.nativeElement.style.top, 10);
1488+
parseFloat(this.dc.instance._viewContainer.element.nativeElement.style.left) :
1489+
parseFloat(this.dc.instance._viewContainer.element.nativeElement.style.top);
14901490
const newSize = this.sizesCache[this.state.startIndex] - offset;
14911491
this.scrollPosition = newSize;
14921492
if (this.scrollPosition !== newSize) {
@@ -1651,8 +1651,8 @@ export class IgxGridForOfDirective<T, U extends T[] = T[]> extends IgxForOfDirec
16511651
}
16521652
const containerSize = 'igxForContainerSize';
16531653
if (containerSize in changes && !changes[containerSize].firstChange && this.igxForOf) {
1654-
const prevSize = parseInt(changes[containerSize].previousValue, 10);
1655-
const newSize = parseInt(changes[containerSize].currentValue, 10);
1654+
const prevSize = parseFloat(changes[containerSize].previousValue);
1655+
const newSize = parseFloat(changes[containerSize].currentValue);
16561656
this._recalcOnContainerChange({prevSize, newSize});
16571657
}
16581658
}
@@ -1700,7 +1700,7 @@ export class IgxGridForOfDirective<T, U extends T[] = T[]> extends IgxForOfDirec
17001700
}
17011701

17021702
public override onScroll(event) {
1703-
if (!parseInt(this.scrollComponent.nativeElement.style.height, 10)) {
1703+
if (!parseFloat(this.scrollComponent.nativeElement.style.height)) {
17041704
return;
17051705
}
17061706
if (!this._bScrollInternal) {
@@ -1719,7 +1719,7 @@ export class IgxGridForOfDirective<T, U extends T[] = T[]> extends IgxForOfDirec
17191719
public override onHScroll(scrollAmount) {
17201720
/* in certain situations this may be called when no scrollbar is visible */
17211721
const firstScrollChild = this.scrollComponent.nativeElement.children.item(0) as HTMLElement;
1722-
if (!this.scrollComponent || !parseInt(firstScrollChild.style.width, 10)) {
1722+
if (!this.scrollComponent || !parseFloat(firstScrollChild.style.width)) {
17231723
return;
17241724
}
17251725
// Updating horizontal chunks
@@ -1744,7 +1744,7 @@ export class IgxGridForOfDirective<T, U extends T[] = T[]> extends IgxForOfDirec
17441744
size = item.height;
17451745
}
17461746
} else {
1747-
size = parseInt(item[dimension], 10) || 0;
1747+
size = parseFloat(item[dimension]) || 0;
17481748
}
17491749
return size;
17501750
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,7 @@ export abstract class IgxGridBaseDirective implements GridType,
33643364
private _sortDescendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
33653365
private _gridSize: Size = Size.Large;
33663366
private _defaultRowHeight = 50;
3367+
private _borderSize = 1;
33673368
private _rowCount: number;
33683369
private _cellMergeMode: GridCellMergeMode = GridCellMergeMode.onSort;
33693370
private _columnsToMerge: IgxColumnComponent[] = [];
@@ -5634,7 +5635,7 @@ export abstract class IgxGridBaseDirective implements GridType,
56345635
if (this.hasCellsToMerge) {
56355636
return this.rowHeight;
56365637
}
5637-
return this.rowHeight + 1;
5638+
return this.rowHeight + this._borderSize;
56385639
}
56395640

56405641
/**
@@ -7864,12 +7865,7 @@ export abstract class IgxGridBaseDirective implements GridType,
78647865
}
78657866

78667867
protected get renderedActualRowHeight() {
7867-
let border = 1;
7868-
if (this.rowList.toArray().length > 0) {
7869-
const rowStyles = this.document.defaultView.getComputedStyle(this.rowList.first.nativeElement);
7870-
border = rowStyles.borderBottomWidth ? Math.ceil(parseFloat(rowStyles.borderBottomWidth)) : border;
7871-
}
7872-
return this.rowHeight + border;
7868+
return this.rowHeight + this._borderSize;
78737869
}
78747870

78757871
private executeCallback(rowIndex, visibleColIndex = -1, cb: (args: any) => void = null) {
@@ -8148,6 +8144,13 @@ export abstract class IgxGridBaseDirective implements GridType,
81488144
} else {
81498145
this._shouldRecalcRowHeight = true;
81508146
}
8147+
8148+
const rowStyles = this.document.defaultView.getComputedStyle(this.dataRowList.first.nativeElement);
8149+
8150+
const border = rowStyles.borderBottomWidth ? parseFloat(rowStyles.borderBottomWidth) : 1;
8151+
if (border) {
8152+
this._borderSize = border;
8153+
}
81518154
}
81528155
}
81538156

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ describe('IgxGrid - multi-row-layout #grid', () => {
940940

941941
// check group size is correct
942942
expect(horizontalVirtualization.getSizeAt(0)).toBe(700);
943-
expect(horizontalVirtualization.getSizeAt(1)).toBe(300);
943+
expect(horizontalVirtualization.getSizeAt(1)).toBe(grid.calcWidth * 0.5);
944944

945945
// check DOM
946946
gridFirstRow = grid.rowList.first;
@@ -968,7 +968,7 @@ describe('IgxGrid - multi-row-layout #grid', () => {
968968

969969
// check group size is correct
970970
expect(horizontalVirtualization.getSizeAt(0)).toBe(700);
971-
expect(horizontalVirtualization.getSizeAt(1)).toBe(300);
971+
expect(horizontalVirtualization.getSizeAt(1)).toBe(grid.calcWidth * 0.5);
972972
expect(horizontalVirtualization.getSizeAt(2)).toBe(136 * 4);
973973

974974
// check DOM

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
let-rowIndex="index" [igxForScrollOrientation]="'vertical'" [igxForScrollContainer]="verticalScroll"
4343
[igxForContainerSize]="calcHeight"
4444
[igxForItemSize]="hasColumnLayouts ? rowHeight * multiRowLayoutRowSize + 1 : renderedRowHeight"
45-
[igxGridForOfVariableSizes]="false"
45+
4646
#verticalScrollContainer (dataChanging)="dataRebinding($event)" (dataChanged)="dataRebound($event)">
4747
<ng-template
4848
[igxTemplateOutlet]="recordTemplate"

0 commit comments

Comments
 (0)