Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p-table: VirtualScroll: on, lazyloading: on without knowing the total number of the data items #17106

Open
leolazos opened this issue Dec 18, 2024 · 1 comment
Assignees
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Milestone

Comments

@leolazos
Copy link

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

@leolazos leolazos added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 18, 2024
@mertsincan mertsincan added this to the 19.0.2 milestone Dec 19, 2024
@github-project-automation github-project-automation bot moved this to Review in PrimeNG Dec 19, 2024
@mertsincan mertsincan added Status: Pending Review Issue or pull request is being reviewed by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 19, 2024
@mertsincan mertsincan self-assigned this Dec 19, 2024
@MichiBaum
Copy link

Just wanna add in Angular 19.0.4 and Primeng 19.0.1 this bug exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Projects
Status: Review
Development

No branches or pull requests

3 participants