How to improve performance for TableView in JavaFX - javafx

I have a TableView with more than 5000 entries. Is there a way to load from database only the first 20 entries (TableView can display a max of 20 entries at a time) and when the user scrolls down, the next 20 entries will be loaded from database. Or do you guys have a better way of keeping the RAM usage to a minimum?

TableView won't create 5000 rows of graphics if the viewport is only 20 rows high. It will probably only have about 25 rows, enough to preload a few rows off screen for performance. Screen table rows are recycled with new table model data as you scroll up and down. So the idea that you can somehow "improve the performance" is a bit out of wack to start with.
The main problem with lazy loading is that it isn't really compatible with a lot of the elements of a TableView. For instance, what should happen when the user clicks on a column header to sort? How big should the scroll cursor be? What happens if the user drags the scroll cursor down to the bottom?
5000 items doesn't seem that large to me. Your table model should only have the data required for row display, which in most cases boils down to a few string and number properties. So unless your table is hundreds of columns wide, your entire table should be a reasonable size. 200 bytes per row is only 1MB for the whole table model.

Related

Qt5 QTreeView with custom model and large data very slow scrolling

I have custom data that I need to display in a QTreeView. I have derived my model from QAbstractTableModel, and made my own implementations of rowCount(), columnCount(), data(), and headerData(). The model has a local QList> to support it, and the data() function is defined to read the values out of that list of lists directly corresponding to the row and column received in the QModelIndex parameter. There are two issues I'm running into.
The first is that the load of a very large file is quite slow, which is understandable. The second is that the scroll action is painfully slow, which I am not really understanding. Turns out that if I pull the scroll handle down, the GUI hangs for about 20 seconds, and then pops back. If I pull the handle a greater distance down, the hang time increases accordingly. If I pull the handle all the way to the bottom of the scroll bar, after waiting for the application to become responsive again, I can pull the handle up and down and get much better response.
It seems to me that QTreeView is only asking for a small chunk of the available data, but when I have pulled the scroll handle all the way to the bottom of the scroll bar, once the application becomes responsive again, it has by that point read all the data.
Is there a way to program for a much more responsive experience with scrolling for large data? I don't mind a longer wait up front, so just something like forcing the view to read all data from the model up front would work.
I have also thought that I could go back to just deriving from QAbstractItemView and controlling how it requests and stores data, only allowing for storing the viewed data, plus a buffer of entries before and after the viewed data. That of course would mean I'd have to control the scroll bar, since the handle sizing would indicate a small amount of data, and I would like it to look to the user as it should for the size of data they are dealing with. Not really wanting to go there if I don't have to.
Two things:
Re-implement fetchMore() and canFetchMore() in your model. See this implementation example. Basically, the two functions allow lazy initialization of your data and should stop ui freezes.
Replace your usage of reset() and dataChanged() to use the insert and remove functionality. Right now, you are forcing the view to recalc which of 100,000 items to show.
use
treeview view;
view.setUniformRowHeights(true);
Then view do n't hangs.

Display product images in a datagrid in 4 columns and X rows (VB.NET)

Hello I am building a POS system and would like to display a list of images all available products for selection.
So for example, if someone picks category: Shirts, a datagrid of images all Shirts in that category should appear.
The grid should show in a 4 by X matrix where X is the number of columns (dependant on the number of products obviously).
So the result should look something like this link (with only the pictures showing and no writing to keep it simple).
Any Ideas at all please? Not expecting code, just some guidance on how to kick this off.
There are a million different ways to accomplish this.
Repeater controls will simply repeat for every result you pass them, and could pretty easily be set to repeat horizontally, and provide a line break every four records. Them you would just need to repeat an image who's source was databound you each image for your products.
That's probably the simplest approach, but you could get all kinds of fancy with client side ui elements, paging, sorting, etc. Just depends on what you need and how long you have to work on this one piece.

Decreasing size of ViewState from DataGrid

I am trying to decrease the load in ViewState that is coming from my DataGrid, but it is not working as I expected. When my page initially runs (and my datagrid is empty), it's viewstate is about 1794 bytes. When I fill my datagrid with EnableViewState="true", ViewState comes out to 4,074,656 bytes, and when I fill the datagrid with the same data but EnableViewState="false", viewstate comes out to 2,477,356 bytes. I know this number is almost cut in half, but it is still a large number (and is proportionate to the size of the grid). Without anything coming from the datagrid, I would expect this to definitely be less than 10,000 (not much larger than the original 1794).. why is it still so high? Is there something else I must do to decrease the viewstate load coming from my datagrid? By the way, the datagrid when filled has about 1600 rows and 27 columns.
I realized the DataTable I retrieved from my data layer class (used to bind my DataGrid to) was also being stored in ViewState[] for sorting purposes (very bad practice), which I just found out stores all of its data in the __VIEWSTATE hidden field.
It was being stored in ViewState[] because I was too lazy to store/retrieve the search option fields and re-query for sorting, not realizing the consequences. Basically, with my DataGrid having EnableViewState="true", my __VIEWSTATE was doubling in size.. I learned a lot from this mistake, and I hope anyone else that stumbles across this learns something too.

Flex : A better way to represnt data from a table having large number of columns

I have to give a functionality on one of my pages is like:
I have data which represents data of a row from a table, and table has many columns.
This data has to be edited, and sent back to the server.
I am showing data in a datagrid, which obviously doesnt look good as we always have one row and that too a large row, so user has to use scroll to look for some values.
I want suggestions for this, like what should i use to make it look better and more user friendly.
I could have hard coded things but considering, if tomorrow table schema or xml respnse change it will break.
Any suggestions will be nice.
If I have clearly understood your problem, you have too much information in a row and you would like too be able to see all of your row data in the meantime.
How about creating dynamically, on a row double click by example, a form popup that would display vertically your columns data ?

Slow sorting on datagrid column with custom item renderer

We have a Flex DataGrid with 3 columns of which one of them has a custom inline itemrenderer that renders an icon in the cell via an Image component, depending on the data in the row.
The problem is now that sorting this column is incredibly slow. It's OK when we only have a few rows of data in there, but as soon as we have a few hundred or thousand of rows, we notice a freeze of several seconds.
Has anyone noticed this and run into the same problem. If so, did you find any good fix for this? I know we could limit the number of rows in the dataprovider, but I'm really looking for a solution to the root problem.
--
Update: some info on the solution: the problem we had was actually not caused by the item renderer. Since we only have 2 distinct values in that column, it was sorting really slow on large data sets. The solution was to write a custom compare function and append some of the other properties to the value that gets compared to make it more distinct.
I haven't seen this with item renderers but I certainly have seen sort get slow when the data in the column is very similar. For instance in my Census benchmark app the Gender column sorts much slower than the Id column. There is a known bug that has a workaround.
If that is not the problem they you will just need to optimize your item renderer. Check out the code the for default DataGridItemRenderer to see an example of a well optimized renderer.

Resources