This is due to the fact that the multiselect mode returns a HashSet as value.
To order the values you have to create a List, iterate over the itemIds and add the objects that are in the set to your list.
Hi,
But I have tried that also. When I get table.getValue() that time it gives me randomly ordered values. How to avoid this so that I could get the list of items in desired order?
The value of a multi-selectable Vaadin component (Table, List, …) is a Set so there is no order. You need to implement the ordering yourself if it is required.
Note that there would not be just one logical order anyway - some want the order in which the items are in the table, others might want MS Windows style of ordering based on dragged item, selection head and the rest of the selection while others might prefer some other order.
Same issue happened for me… It looks really weird to have a random order. We should (at least) have the same order (like: the last element to be selected could be added at the end of the list) every time we do the same selection to avoid unexpected results.
Some questions about that:
Why is it not a LinkedHashSet instead of an HashSet in the current implementation?
Do you plan to implement something to guaranty the order in Vaadin 7?
In the current Vaadin 7 plans, no changes are planned for this.
The set on the server side could be a LinkedHashSet, but I believe that would not help much due to how the data is passed between server and client and potentially modified on both sides.
Is there any other approach to get the selection in the tables current order now? Is it still necessary to iterate over the complete item ids given by table.getItemIds() ???
Even the docu says this should be avoided…
Multiselect Grid and TreeGrid in Vaadin 8: is there now an easy way to get the selectedItems in the order like displayed from top to bottom? How would one accomplish that in the TreeGrid?