How can I easily re-order items in a table? I have “move up” and “move down” buttons that should move the selected item (only one selected) up or down when clicked.
Currently I make a IndexedContainer that is used as table container, and “move down” does roughly the following:
Get the currently selected item
Get the id from the IndexedContainer using indexOfId()
Get all item properties and store them temporarily
Remove the selected item from the table/container
Re-add the item to the container at position (id+1)
Loop through all container properties and re-set them for the item.
This seems unneccessary complicated for such a simple task.
Thanks! Sounds great that you plan to include that functionality!
Another question:
Will the same fix work for the Tree component? I need to move a tree node up/down and can’t seem to find any good way to do it. I can’t even find a method for getting the next / previous sibling in the tree.
I am looking for exactly that functionality in the HierarchicalContainer. Artur’s solution looks great but how can I add the methods to HierarchicalContainer? HierarchicalContainer is a Vaadin class and it’s fields are private which means I can’t even subclass it, right?