I’ve got a detail table that has sequenced items, and I’ve got a pair of buttons for moving items up/down in the table. The button works (I’m just working on the Up button first). The sequences swap correctly (2 becomes 1, 1 becomes 2 for instance)… but the table doesn’t fully redisplay.
What I mean is if I have 2 items: sequence 1, TEST 1, sequence 2, TEST2, I hit the Up button on item #2, 1 and 2 swap correctly (we now have sequence 1 TEST2, sequence 2 TEST 1)… but then the table is displayed in the order sequence 2 TEST 1, sequence 1 TEST 2. If I confirm all the changes, going all the way out to the browse screen, and go back in, it displays in the correct order, but it will not while “live.”
I’ve tried table.repaint() and also table.sort(“sequence”, Table.SortDirection.ASCENDING) followed by table.repaint() - but it just doesn’t redisplay with the new, correct order.
You can swap items in the same way as it is done in OrderEdit.java : determine the index of the currently selected item and then swap the items using collectionContainer.getMutableItems().set(idx, item). In this case, a table should update its view. As far as I understand, you’re implementing Up/Down buttons in a browser screen, so in this case, you need to commit changes manually either after each swap or by a custom button.
The table in question is a detail table on an edit screen for its master. It represents diagnoses on a patient’s registration. The order is important as to primary DX, secondary DX, etc - so the user needs to be able to easily order/reorder them. The entity has 3 attributes - a ref to the parent/master (the registration), the sequence, and a ref to the DX code table (lookup). Of course, only the sequence and DX code are displayed in the table.
The up/down buttons manipulate the sequence - that all works fine and the sequences themselves update visually correctly but the table does not redisplay in the new order unless I do the following:
Nevertheless, it seems that the code from this sample cuba-sample-sort-composition might fit your needs. If it’s not, could you please attach a demo project or at least share a code snippet on how you manipulate the sequence.
A sample / demo project is crucial to have when talking about a problem in order to provide a solution. It is not intended to take your existing production project. Create a new example project, take a similar domain (or just exchange domain names), put as little entities in it as possible, reproduce the bug.
If you can reproduce it, great - put it in here and we will try to figure out.
If you can’t reproduce - great. Try to identify what is different in your example. If you find something: repeat the process.
This has some major upsides:
you will learn a lot. Isolating a problem is a very important skill to have. You will learn about the framework, about the patterns of your domain model, some internals of the framework and so on.
You will increase the likelihood that you will get an answer. Think about it: this is a free service. A lot of people don’t get paid to answer your question. Those who get, they can still pick the question that will give them a quick win. Since you probably don’t pay for the answer - if you do your very best to help the people to help you, that increases your chances to get a proper answer fast…
You created an abstract example that fulfills a community purpose. If the example is not polluted with the domain you are in but instead with a domain everyone understands, you do the community a favor, because of the likelihood that other people have a similar question.
You are a good role model for other community members. When other people see you creating great questions, doing good examples, etc. They will start mirroring your behavior. This leads to overall better examples, faster answers, etc.
@gorelov that code (of course!) works perfectly. Is there any practical advantage to using that approach vs. the approach I’d hacked out before (that being .sort() followed by .repaint())?
@mario thanks again for the reminder about community. I’ll come up with an example project the next time something like this arises. Luckily the framework is so very straightforward and logical that it doesn’t happen too often.
A table column has three possible states: sorted acs, sorted des, unsorted. You force a column to be sorted acs, but if user interact with a column and make it unsorted, then your sequence will be broken. If you change the items order in the data container, then the unsorted state will have the required order.