Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Lazy loading with DataProvider
I tried the new DataProvider interface from Vaadin 8 and it worked very well. From Vaadin 7, I used viritin addon which does pretty the same thing.
However, I noticed something strange with lazy loading. When I used viritin, the data is fetched when I scroll down my grid.
Now with Vaadin 8, all data is loaded without scrolling.
Here is my trace from EclipseLink (without grid scrolling and calling dataProvider.refreshAll)
[EL Fine]: sql: 2017-03-20 12:05:31.982--ServerSession(6167002)--Connection(16516457)--Thread(Thread[http-nio-8080-exec-2,5,main])--SELECT id AS a1, name AS a2, description AS a3, version AS a4, created AS a5, updated AS a6 FROM Region ORDER BY name ASC LIMIT ?, ? bind => [0, 40] [EL Fine]: sql: 2017-03-20 12:05:32.607--ServerSession(6167002)--Connection(16516457)--Thread(Thread[http-nio-8080-exec-11,5,main])--SELECT id AS a1, name AS a2, description AS a3, version AS a4, created AS a5, updated AS a6 FROM Region ORDER BY name ASC LIMIT ?, ? bind => [40, 3]
As you can see, there are 2 queries sent to my database. For your info, my grid only show 10 rows at a time. I must scroll down to see all rows (43 in all).
Is this a bug?
I have seen the same double queries when the page/view is first loaded when using the lazy loading. Additionally I noticed that the first 40+ entries are repeated in the grid.
The first 40 rows you see requested are the assumed default content for the Grid so we don't render an empty Grid at start. Grid on the client-side tries to maintain a reasonable cache so that rows are not requested on every single scroll, but rather keep up a buffer back and forth to keep it nice and smooth. The size of the cache depends on the displayed row count of grid and can be modified by changing the caching strategy on the client-side. The initial rows to send is set by the server and can be modified through grid.getDataCommunicator().setMinPushSize(initialPushCount)
I hope this has given some insight to how the data sending and requests work.