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

TableView Example With Database #11

Open
davidbio opened this issue May 29, 2023 · 3 comments
Open

TableView Example With Database #11

davidbio opened this issue May 29, 2023 · 3 comments

Comments

@davidbio
Copy link

Hi @jjenkov,

I don't know whom to ask and as an experienced JavaFX dev, I thought you might be able to help me with this.

I am trying to find examples or ideas for how to connect a JavaFX TableView with a database.
The thing is I don't want to populate an observable list with all items because there are millions of rows (and few columns). It doesn't make any sense (memory and performance-wise) to that. Also, sorting and filtering is done by the database (local Lucene) and it would be a waste to use JavaFX sorting and filtering.

In SWT I can easily create a virtual table, redirect the sorting and filtering events to the database, and populate the table as I wish.
Is there anything similar I can do with JavaFX TableView? The only advice I found so far is to populate the table with all data (not an option), or to "not load so much data".

I am grateful for any advice or thoughts on this.

@jjenkov
Copy link
Owner

jjenkov commented Jun 1, 2023

Hi @davidbio ,

As far as I know, JavaFX TableView also uses a virtual model of some sorts - where the TableView only creates visible table cells for the rows that are actually currently visible within the TableView. The TableView handles that virtualization automatically when you use a backing ObservableList . However, I am not exactly sure how to connect a TableView to a data source outside of the Java VM. Somehow you would have to tell the TableView how many records there are in total, and when you scroll inside the TableView, have it fetch the corresponding rows from the backing data source. Not sure exactly how to do that.

I would recommend that you try asking on Twitter - and use the hashtag #javafx when you ask. There are a good deal of JavaFX developers watching that hashtag. Also, as far as I remember, there was a developer that made a database GUI in JavaFX. Maybe that developer has an idea too.

@jjenkov
Copy link
Owner

jjenkov commented Jun 1, 2023

I less-than-ideal work-around could be to detect how many "pages" of records a given SQL query would result in (using the same SQL statement with a count on first), and then add a page navigation control above the table. Then the TableView only displays / contains the records for a single page of data. When the user clicks on the next page, the next page is then loaded from the database.

It's not as smooth as infinite scrolling with automatic loading of data in the background - but it could theoretically work.

@davidbio
Copy link
Author

davidbio commented Jun 2, 2023

Thanks for your quick reply!

Yes, I have read that JavaFX is virtual and only the visible columns are represented as Java objects, etc.
That's very nice, but having millions of entries in an observable list and sorting, as well as filtering on that list doesn't make any sense to me. I wished there was a defined approach to trick JavaFX TableView into showing data from a database instead of implementing this manually.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants