Table lazy virtual scroll triggers multiple separate calls to onLazyLoad()
function
#9316
Labels
LTS-FIXED-9.2.0
Fixed in PrimeNG LTS 9.2.0
LTS-FIXED-10.0.5
Fixed in PrimeNG LTS 10.0.5
Type: Bug
Issue contains a bug related to a specific component. Something about the component is not working
Milestone
I'm submitting a ... (check one with "x")
The current implementation of Table
onScrollIndexChange()
uses aforEach()
loop to trigger separate calls toloadPage()
. For example, on initial load of the table, when thepageRange
is calculated to be[0,1]
, two separate lazy events are triggered. e.g. one load for rows 0-40 (page 0), and another load for 40-80 (page 1).As a result, the user sees the table starting at row 40, not row 0.
(Edit:)
Here is a Stackblitz example of the problem. Load it and note that the ID of the first row is 101 and not 1. https://stackblitz.com/edit/primeng-tablevirtualscroll-lazy-bug?file=src%2Fapp%2Fapp.component.ts
The example used in the docs actually keeps ALL of the previously loaded pages in the virtual array, rather than just the rows for the last requested page. This isn't feasible for large data sets, since that virtual array will get gigantic for large data sets. My demo only keeps the current page's data in the virtual array, which is how anyone with a large data set would need to use the lazy virtual scrolling.
On a related note, as my bug demo shows, setting [totalRecords] seems to have no effect on informing the table what the total row count should be.
(end edit)
I'm not sure what the logic was to have
onScrollIndexChange()
trigger multiple differentonLazyLoad()
emits, but that seems to be the root of the problem. I'm also not sure what the point of using a range array is, since as far as I know, only one page at a time should ever be loaded.So it looks like the two options to solve this would be:
A) Drop the use of pageRange and just use the index to load the page index being requested. E.g:
Or B) Move the emit for
onLazyLoad()
intoonScrollIndexChanged()
and only fire it once, with the cumulative data on the pages loaded. Something like:The text was updated successfully, but these errors were encountered: