Order of selected items in multiselect table ?

When having a table in Multiselect mode, we see that the order of the getValue() returned collection
seems to be random.

I would have expected (or better wished) to get the list of selected items
ordered in the same way as they are shown in the table.

Since we use drag&drop to move multiselected rows between tables,
we wish to retain the order when dropping them on the target.

Is there a solution to having the selected items in the same order as displayed in the table ?

Or do we have to sort them ourself (probably via indexOfId() when the container supports it).

Thanks

André

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.

Ok,

thanks

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.

Hi,

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:

  1. Why is it not a LinkedHashSet instead of an HashSet in the current implementation?
  2. Do you plan to implement something to guaranty the order in Vaadin 7?

Thanks.

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?

Thanks in advance!