Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Paging table, lazy loading via JDBC
I know this has been asked a few times before, but is the JPA Container since my best bet to analyze when looking for a way to show a paging table that the user can scroll through when my data comes from JDBC?
Is there a more straightforward scheme based on IndexContainer? Just not sure since that seems to want all the data loaded.
I am interested perhaps in using IndexedContainer, but cannot tell how to do lazy loading with it. Presumably I'd need to override 'sort' and other methods to re-run the query on the server, and perhaps the filters so they can also be done on the server.
But how do I trick it into thinking it has some number of rows/items larger than the ones stored in the container so I can page it on the server as it pages on the client?
And would most people just use LIMIT/OFFSET to handle paging on the server? Seems like cursors and the like won't easily work in a web world (don't want to keep cursors open for a long time, or worry about when you can close the cursor or have multiple cursors, etc.), and this gets even crazier when the user can change the sort/filter criteria.
About a year ago, I contributed some code to the Incubator, which allows you to do paging and lazy loading.
Searching the forum for posts to help you out here, I see that Mattias contributed a a useful extension here which I completely missed at at the time - sorry Mattias! - which I will try to incorporate shortly.
In short, though, extending IndexedContainer is not really a go-er, but implementing your own container is totally achievable, and hopefully these will give you a pointer.
Oh, and yes, LIMIT and OFFSET (or your DB equivalents) are the only practical approach for this.
Thanks, Charles. I'll take a look at the PagingComponent. Is this still just in incubator, or are you putting this into the Directory?
I'll also take a look at Mattias's extension as it relates. It sounds like you will be putting that into the "mainline" code shortly. Any idea when since I may prefer to just wait until it's all together before I study it (there are so many things to study I can wait a bit!).
It sure would be nice if Vaadin decided to have such a Container made generally available as moving through large datasets is not uncommon.
Thanks on the LIMIT/OFFSET which makes sense. How do you know how many total rows are possible from the query? Do you put a COUNT(*) and just get that overhead for each of the "LIMIT" rows?
I know that cursors/fetch can be more efficient, but seem to work only in batch updating, not in online viewing where sorting/filtering takes place.
How does your component work with column sorting on the Table? Does it just not use enable it, or does it just resort what is visible, or do you somehow capture it, issue a new DB query and then repopulate the container?
After looking for and not finding a lazy loading container with sort support I have added my 2 cents to the Addons. The Lazy Query Container is licensed under Apache License 2 and the source is at github:
The container can be bound to for example WebService client or JDBC connection by implementing QueryFactory and Query interfaces.
If someone is interested in collaborating over this then just fork the project in github and send me pull request when you have something you wish to commit to the main branch.
Hi, i just finalized lazy loaded paged table example. More info is on github: https://github.com/ondrej-kvasnovsky/lazy-loaded-paged-table. I think you might find it useful.