-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Table lazy virtual scroll not called on last page #8890
Comments
Same problem. |
Same problem here. |
3 similar comments
Same problem here. |
Same problem here. |
Same problem here. |
@cagataycivici can you tell us if this scenario has been tested? In our case, we're using the new "flex" scrollHeight property, within a container that has a dynamic height (basically starts where it is and expands up to the bottom of the page) set with But even after switching back to a fixed size in px for scrollHeight, we've noticed that the table still doesn't fire the Side note: I feel like your components should use the coerceBoolean utility provided by the Angular CDK to avoid misinterpreting booleans passed as strings, which are truthy (non empty strings). |
Same problem here... |
I'm having the same issue |
I'm having same problem with virtual scroll & lazy load (data from backend) in p-table. |
Having the same issue too. I looked into the table code and found out, that virtual scrolling is explicitly preventing lazy loading at
I'm going to look deeper into it for finding the reason that the scrolling does not activate the lazy loading. EDIT: I would consider this issue as closed then? |
No, the problem still shows in version 9.1.2, and does not only affect the initial load. This is a MAJOR problem. |
We stuck on version 9.0.6 as well and not able to update to all newer version due to this issue. |
I am opening a new issue to try to attract attention on it, because it seems that nobody at Prime cares about it. |
We still encounter the virtual scroll issue with lazy load from server after upgrading primeng to 9.1.2. Please spend more time to fix it. Thanks. |
I had hoped that the issue would be fixed with the new version 9.1.2 since the online demo table seems to work fine. |
I was about to subscribe to this issue because I experienced the same problem, but then I noticed there's simply a change in the API between the pre-CDK version of the virtual scrolling and the one since 9.1, so just in case you guys (or any other reader) fell into the same trap: Previously the Take a close look at the demo implementation: https://stackblitz.com/edit/primeng-tablevirtualscroll-demo?file=src%2Fapp%2Fapp.component.ts HTH |
I can confirm @chromey's observation. I noticed that just one dummy entry at the end of the array is enough to make virtual scrolling work. I'm using the following in an OData helper model for the table. const loadedItems = response.value;
if (opts.isVirtualScrolling) {
const currentItems = opts.event.first !== 0 ? this.items : [];
if (currentItems.length && currentItems[currentItems.length - 1] === undefined) {
// Remove last dummy entry.
currentItems.pop();
}
// Since we want to avoid using OData $count with virtual scrolling:
// total count is reached when we get less items than we requested.
const isTotalCountReached = loadedItems.length < opts.event.rows;
// Concat items and trigger change detection.
// If we want more items to be loaded: add one dummy entry.
this.items = Array.prototype.concat(currentItems, loadedItems, isTotalCountReached ? [] : Array.from({ length: 1 }));
// console.debug(`## OData: previous: ${currentItems.length}, loaded: ${loadedItems.length}, current: ${this.items.length}, ` +
// `end reached: ${isTotalCountReached ? "yes" : "no"}, total: unknown`);
}
else {
this.items = loadedItems;
this.pager.itemIndex = opts.event.first || 0;
this.pager.totalCount = response["@odata.count"] || 0;
// console.debug(`## OData: loaded: ${loadedItems.length}, total: ${this.pager.totalCount}`);
} |
@Casimodo72 But how would you do that with an Observable stream? For example when you pass data from a http request directly into the p-table. I don't see how your approach is a good solution to getting virtual scrolling to work. Why don't they just rely on the totalRecords Attribute when virtual scrolling is active, like with the paginator? |
@mrdlink :
Not sure what you mean exactly. I use a tiny helper class that acts as a view model for collection based components. PrimeNg's table component binds to the "items" field on my view model. private loadCore(opts: PrimeNgCollectionLoadingOptions): Observable<ODataResult<TItem[]>> {
return new Observable((observer: Observer<ODataResult<TItem[]>>) => {
const queryInfo = this.buildODataInfo(opts);
this.isLoading = true;
return this.httpClient.get<ODataResult<TItem[]>>(queryInfo.url)
.pipe(finalize(() => {
this.isLoading = false;
}))
.subscribe((response: ODataResult<TItem[]>) => {
const loadedItems = response.value;
if (false) {
// TODO: REMOVE: Just for dev purposes.
let index = queryInfo.skip;
for (const item of loadedItems) {
index++;
item["index"] = index;
}
}
if (opts.isVirtualScrolling) {
const currentItems = queryInfo.skip !== 0 ? this.items : [];
if (currentItems.length && currentItems[currentItems.length - 1] === undefined) {
// Remove last dummy entry.
currentItems.pop();
}
// Since we want to avoid using OData $count with virtual scrolling:
// total count is reached when we get less items than we requested.
const isTotalCountReached = loadedItems.length < queryInfo.top;
// Concat items and trigger change detection.
// If we want more items to be loaded: add one dummy entry.
this.items = Array.prototype.concat(currentItems, loadedItems,
isTotalCountReached ? [] : Array.from({ length: 1 }));
// TODO: REMOVE: console.debug(`## OData: previous: ${currentItems.length}, ` +
// `loaded: ${loadedItems.length}, current: ${this.items.length}, ` +
// `end reached: ${isTotalCountReached ? "yes" : "no"}, total: unknown`);
}
else {
this.items = loadedItems;
this.pager.itemIndex = queryInfo.skip;
this.pager.totalCount = response["@odata.count"] || 0;
// TODO: REMOVE: console.debug(`## OData: loaded: ${loadedItems.length}, total: ${this.pager.totalCount}`);
}
observer.next(response);
observer.complete();
}, err => observer.error(err));
});
} |
@Casimodo72 Yes this is what I meant. It seems a bit hacky though. |
@mrdlink : You are right, it seems hacky - because it is incorrect :-) I just played a bit more with it and learned that is doesn't matter if I add a dummy entry at the end or not. So one can happily remove that. What I also experienced: Sometimes the lazy loading with virtual scrolling does not work initially for me. Maybe that's why I got confused and tried to add the dummy entry. By the way: I'm using PrimeNg v10.0.0-rc.1. Forgot to mention that. |
+1 |
@Casimodo72 Okay, but this still does not work for me, because I use |
The problem that we get after sorting/filtering comes from ScrollableView.prototype.loadPage. There we have the following check - !this.loadedPages.includes(page). So the way it works is that while you are scrolling you are adding loadPages number into the array but after sorting/filtering it does not get cleared. Therfore, while you are at first page after sorting the onLazyLoad will not trigger because it is already included in loadedPages. All you need to do to fix that is to call the clearCache() method on p-table. This will clear the loadedPages and will start emitting the onLazyLoad event again. I hope this helps. |
I can't seem to replicate on 10.0.0-rc.4, fixed a couple of issues on virtual scroll but could not see this one. Please note that virtual scrolling since 9.1.0 is not backward compatible since we switches to CDK for it. If the issue still persists, please create a new ticker with a stackblitz case demonstrating the issue and our team will review. |
[x ] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
The text was updated successfully, but these errors were encountered: