Sorting from DB for a table column


I have created a table which is reading the data from DB. The table columns are sortable. But what I observed is when I click on column name for sorting it sorts the record for the page displayed. i.e. in memory sort of the record fetched in the current page.

Whereas my requirement is the software should refetch the data from DB in the sort order.

Thanks in advance!!



Instead of doing a query and then adding your restuls to an Indexed/BeanItemContainer, you’ll need to implement your own Container that implements Container.Sortable - and then ensure that it uses the appropriate columns to affect the generated SQL.

There are several Vaadin add-ons that already do this ; I cannot vouch for them, as I have not used them myself (our commercial closed-source project has it’s own implementation that calls our own service layer to do the db-search).

Lazy Query Container

JPA Criteria Lazy Container

JPA Container
- (note that this particular addon has some special licensing conditions, i.e. need to pay if it’s used in a commerical product)