From 3141f09df01da36a3a1f43bd37e14f6b98d979af Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 2 Feb 2024 10:57:28 +0000 Subject: [PATCH] Fixed #5078 - DataTable: VirtualScroller Resets Scroll Position to top on lazy load more data --- components/lib/virtualscroller/VirtualScroller.vue | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/lib/virtualscroller/VirtualScroller.vue b/components/lib/virtualscroller/VirtualScroller.vue index 7b8d0b96c..7e9b9e3c4 100644 --- a/components/lib/virtualscroller/VirtualScroller.vue +++ b/components/lib/virtualscroller/VirtualScroller.vue @@ -305,7 +305,7 @@ export default { Promise.resolve().then(() => { this.lazyLoadState = { first: this.step ? (both ? { rows: 0, cols: first.cols } : 0) : first, - last: Math.min(this.step ? this.step : last, this.items.length) + last: Math.min(this.step ? this.step : last, this.items?.length || 0) }; this.$emit('lazy-load', this.lazyLoadState); @@ -324,10 +324,10 @@ export default { this.content.style.position = 'relative'; this.element.style.contain = 'none'; - const [contentWidth, contentHeight] = [DomHandler.getWidth(this.content), DomHandler.getHeight(this.content)]; + /*const [contentWidth, contentHeight] = [DomHandler.getWidth(this.content), DomHandler.getHeight(this.content)]; contentWidth !== this.defaultContentWidth && (this.element.style.width = ''); - contentHeight !== this.defaultContentHeight && (this.element.style.height = ''); + contentHeight !== this.defaultContentHeight && (this.element.style.height = '');*/ const [width, height] = [DomHandler.getWidth(this.element), DomHandler.getHeight(this.element)]; @@ -342,7 +342,7 @@ export default { } }, getLast(last = 0, isCols) { - return this.items ? Math.min(isCols ? (this.columns || this.items[0]).length : this.items.length, last) : 0; + return this.items ? Math.min(isCols ? (this.columns || this.items[0])?.length || 0 : this.items?.length || 0, last) : 0; }, getContentPosition() { if (this.content) { @@ -504,8 +504,8 @@ export default { if (this.lazy && this.isPageChanged(first)) { const lazyLoadState = { - first: this.step ? Math.min(this.getPageByFirst(first) * this.step, this.items.length - this.step) : first, - last: Math.min(this.step ? (this.getPageByFirst(first) + 1) * this.step : last, this.items.length) + first: this.step ? Math.min(this.getPageByFirst(first) * this.step, (this.items?.length || 0) - this.step) : first, + last: Math.min(this.step ? (this.getPageByFirst(first) + 1) * this.step : last, this.items?.length || 0) }; const isLazyStateChanged = this.lazyLoadState.first !== lazyLoadState.first || this.lazyLoadState.last !== lazyLoadState.last;