Get the last selected row in Table

Hi everyone,

I had a Vaadin Table with 20 rows and multiple selection mode.

Next, I selected several rows in the order as following: row 3, row 19, row 10, row 14, and row 7

I expected to have that order in the getValue() method but it’s not

As far as I understand, the getValue() returns a Set object whose element order is unpredictable.

I don’t know how I can get that order or at least the last selected item, which is row 7 in this case. Please help!

Thank you very much!

Hi,

as far as I know there is no way to do this without some modifications. The Table extends AbstractSelect which uses sets for the multi selection value. You might be able to create some kind of workaround by e.g. adding itemClickListener to your table and storing the click order on the server side in an ordered collection. Then when you get the current value set you could just look up the order from the list.

-Tepi

As Teppo said, changing what getValue() returns into something ordered would require modifications both on the client side and the server side.

On the client side, the type of VScrollTable.selectedRowRanges would have to be some ordered collection and on the server Table.handleSelectedItems() should create something else than a HashSet. Also, the logic in AbstractSelect (shared with list select components, combo boxes etc. - especially the methods getValue() and setValue()) assumes a Set.

While the number of lines that would need to be changed might be small to enable this, copying the large classes VScrollTable and Table would introduce considerable maintenance overhead in your project.

Thank you Tepi!

It almost works now but when I use arrow keys to select, it does not :frowning:

@Henri Sara: I don’t know exactly what to do following what you said, but I will try

Oh yeah, I did not think of the keyboard navigation… Unfortunately I can’t think of a workaround for that one :frowning:

-Tepi