I'm using Nattable for almost all my tables in my application. Now an user reported an issue regarding the selection in Nattable.
When my application loads data the data is shown, when the user select an item just after the data loading, it will remove the selection. When the user wait a few seconds and does the selection again it holds.
Is this a known behavior of Nattable? For me it looks like the data is still loading when the first selection took place. The data load is 11K items with multiple cell labelers.
Without seeing the details it is hard to tell. Actually I wonder how something is rendered while the data is still loaded. But I suppose you have some interesting lazy loading mechanism to make the table accessible fast.
From my experience the behavior you describe happens because of a StructuralChangeEvent. Once the data is completely loaded such an event is fired to update all layers accordingly. A structural change is used to completely clear, that also implies the selection when using the default SelectionModel. The selection in that model is stored by row index. But as a structural change means this could have been changed, the selection is removed to avoid that something is shown selected that was not selected before.
Either you use an extended selection model like the RowSelectionModel or the PreserveSelectionModel or you double check when the StructuralChangeEvent is fired and if you can deal with that. But I suppose an alternative selection model should be more interesting with regards to your data loading mechanism.
Related
I have a list grid which contains thousands of records. I can update any row in this list grid. After updating a row, I need to remain focus to the particular row.
From the RecordClickEvent, I take the index of the record. When I fetch the data again I've used below methods.
listGrid.selectRecord(recordIndex);
listGrid.scrollToRow(recordIndex);
If I update a record within first 75, it works nicely. How can I remain the focus, if I update a record not in first 75 records?
You must be doing something in your code that breaks this default behavior (of keeping focus on the edited record), because I have a paged editable ListGrid with close to 20.000 records, and when I update any record, I retain focus on the edited record without doing anything specific. Without looking at your code, it's not possible to know what can be wrong in your case, that focus is lost after updating one record.
Take a look at this particular demo for an example of what I mean regarding the default behavior.
By the way, what you are trying to do could be accomplished by loading your data page by page, until you get past the recordIndex, but take into consideration that this could be a very disconcerting user experience.
I intend to write an JFX-Application that displays data from database tables that contain up to 1M entries. Unfortunately, the standard API makes it difficult to support lazy loading. Reading the whole table is not an option (even though it performs well up to 100K entries).
Paging can be accomplished using a custom list class provided as model to the TableView. However, I also need to control the sorting behaviour of the TableView, since in my case, this would be left to the dbms.
An ugly solution is to make the columns unsortable, and add a Click-Event listener to the Column-Header. Apart from the coding, this also makes it impossible to display the current sort order in the usual way.
It is possible to listen to a change to columnSortOrder, but the standard sorting mechanism is still applied. What I would like to be able to do is display the standard ascending/descending icon in the column header while having full control of the sort behaviour of the TableView.
[Edit: In short, I want to implement lazy loading. I want a TableView that behaves exactly like normal TableView but does not sort the list when the user clicks on a column header. However, the sort order should still be displayed in the column header label.]
Is that somehow possible to achieve?
Many thanks for your answers in advance!
For reference:
This has been added to JavaFX-8. One can use TableView.setSortPolicy(...) to customize sorting.
Skimmed through the Eclipse API doc and found no mentioning of this event. Could I have missed something? I'm building something that lists all table columns in a given table, and it needs to be automatically updated if the set of columns in the Table changes, so I need to listen to the Table structure changes and update my list accordingly.
What you are looking for doesn't exist. You could add dispose listeners to the TableColumns, and that could tell you when one is removed, but there are no events for telling you when widgets are created. You might be able to "fake it" by tracking control events on the table columns with TableColumn#addControlListener, but this is iffy. If you have control of the tables you could do something more advanced by wrapping them in a dynamic proxy that could perform that function for you.
I need to build a table from SQL select result set. I want to add some paging functionality to the table because the result set can be very large. There was many discussions how to do the paging at the SQL level. But how to implement the paging at the GUI level? I have two ideas:
Do the paging in a web UI style - for example google search result paging;
"Excel style" - the scroll pane where the table resides expands as user scrolls down.
The second one looks nicer but complex to implement. When to do SQL select for a next chunk of data so that a user haven't wait for it. There should be some "read ahead" logic? What will happen if user scrolls quite quickly? What to do with rows that aren't visible any more to have constant memory usage?
Maybe there is already such a table component or good examples? Or maybe this good looking table functionality is unworthy of efforts to implement it?
You could do everything directly into your TableModel, there is no need to change something in the UI(well you migh show something in the UI - a status - but you don't need to change how JTable renders itself).
Just implement a JDBCTableModel which will have :
count the results and return this value as getRowCount().
have a background thread which brings page X(row X to row X + page_size) in memory
if the view(JTable) asks for a row which is not there(page not loaded) show a message "Loading data..." somewhere in left or rigth top corner and return empty cells.
Paging doesn't makes sense for a Swing application, it was invented before the current fancy AJAX libraries could implement table scrolling(see http://www.ext-livegrid.com/).
The people who have built paging tables for AJAX libraries have obviously thought about this a lot, so you may be able to learn from them if you can't find something already built. Since you are using Java, note that you can find paging tables written in Java for GWT. See these SO threads:
GWT paging widget
Best pageable table implementation in GWT
The ideas (and much of the code) for your implemenation may be found in the open source projects mentioned.
Say you retrieve 100 records, and display them on a page. The user only updates 2 of the records on the page. Now you want to update only the two records, and not the other 98.
Is it best to have one submit on the page, then somehow know which 2 are updated, then send only those two to the db for an update?
What does the "somehow" look like?
Or, would you have an update-submit button for each row, and have it only update the record its tied to?
Of course there are different ways you could do this. In general, you can save yourself some trouble and server-side processing by using Javascript to assemble your POST data for only the records that have changed. Two thoughts on how this might work:
1) Go the ajax route and do live-editing. So records are presented in a table and appear to be non-editable. When a user clicks a particular row, that row becomes editable by using Javascript to create the appropriate html form on the fly. Then have either a submit button or some other handler (say, moving focus to another table row) which will trigger the POST which updates the DB (asynchronously via your preferred ajax method). Happily the mainstream Javascript frameworks can help a lot in this area.
2) Checkboxes - whenever a row is edited, its checkbox becomes checked. When the submit button is clicked, use javascript to post the POST data by grabbing everything in row whose checkbox is checked. A user can un-check a box to cancel changes to that row before submitting.
Ajax it using jQuery or some other JavaScript library and put and update button on each row.
There are many answers to this question and to some extent they depend upon your development tools and the "feel" of the site.
If you were implementing Ajax calls to do the updates on a line by line basis then this would logically seem right to have a button per line and then update it with an Ajax call when a line was changed.
This is also just the scenario that disconnected data sets were designed to solve and ADO.net handles these very well.
So as ever, the answer is "It Depends!"
You can use JavaScript to mark each field as changed when a user changes an input field. Create a hidden fields that has the id of the row you are updating, and dirty flag. (like is_dirty_$id) In JavaScript, create an onChange handler that sets the hidden field as dirty. when any input is changed.
Alternatively, you can create hidden fields for each real field you display. the hidden field would contain the initial values. check each field on the server side to determine what has changed.
You probably want to store a last_modified date as a hidden field for each record. This way if another user updates the same record, you can display an error message saying "this record has been updated by another user" or similar.
One submit button. I could foresee case I might use more then one, but in the general case just one. (Note, this looks like a web page question to me, so I'm answering with that assumption.)
There are 3 ways that come to mind which you could handle the tracking changes:
JavaScript: Put a onChange() function on the controls that update a hidden field. If that hidden has a value, then update the associated record. Requires JS on the browser, and doesn't tell you which fields to update, just which records.
Lots of form fields: Put a hidden field out with each control and compare them all when they come back. This would be ugly, but it would allow you to know which fields to update (not just the record). It would also allow you to know if someone undid a change that started.
Sessions: You could place the original values in session variables, then do the comparison when the values come back. This would be a little more elegant then lots of hidden fields, and less open to people playing with the posted back data (since you should never trust anything that comes back, even in hidden fields). Requires cookies on the browser and sessions on the server technology.