p-table: VirtualScroll: on, lazyloading: on without knowing the total number of the data items #17106
Labels
Status: Pending Review
Issue or pull request is being reviewed by Core Team
Milestone
Describe the bug
SAME BUG AS IN #13346 THAT WAS CLOSED WITHOUT TAKING ANY TIME FOR CHECKING AFTER 1,5 YEARS!!!!!
Describe the bug
I have a table with virtualScroll = on, lazyLoading = on, scrollHeight=flex
I have a dataset, which is expanded through lazyloading. At the init state I do not know the total number of the data items. So I init the data with an empty array which is filled as I scroll down through the table. My problem is that everytime new items are loaded and added to the data array, the table jumps back to the first item (scoll postion 0 ).
I debug it and what I found is:
The problem is, that everytime the data array is extended (lazy loaded items added) the code in primng-scroller.ngOnChanges():
if (this.initialized) {
const isChanged = !isLoadingChanged && (simpleChanges.items?.previousValue?.length !== simpleChanges.items?.currentValue?.length || simpleChanges.itemSize || simpleChanges.scrollHeight || simpleChanges.scrollWidth);
if (isChanged) {
this.init();
this.calculateAutoSize();
}
}
causes the call of the init()-method. isLoadingChanged is false, and the length of the value is now greater then before -> call init().
In the init method the method calculateOptions() is called. There the code:
if (this._lazy) {
Promise.resolve().then(() => {
this.lazyLoadState = {
first: this._step ? (this.both ? { rows: 0, cols: first.cols } : 0) : first,
last: Math.min(this._step ? this._step : this.last, this.items.length)
};
this.handleEvents('onLazyLoad', this.lazyLoadState);
});
Because here _step is the number of rows the lazyLoadState is resetet to first: 0 and last to the value of _step. And exactly this causes the jump back to the first item in the table (or scroll position 0).
This is sure not a desired behaviour.
Environment
Windows, PrimeNG 15.4.1, Angular 15.2.9
Reproducer
No response
Angular version
15.2.9
PrimeNG version
15.4.1
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
18.14.0
Browser(s)
Chrome, Edge, Firefox, Safari
Steps to reproduce the behavior
No response
Expected behavior
The table should stay on the last scroll position after data items are loaded and added to the data array
Environment
Windows, PrimeNG 17.18.13, Angular 18.4.x
Reproducer
No response
Angular version
18.4.0
PrimeNG version
17.18.13
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
18.19.x
Browser(s)
No response
Steps to reproduce the behavior
No response
Expected behavior
No response
The text was updated successfully, but these errors were encountered: