Table sort by multiple columns

Hello,

with the vaadin table it’s possible to easily sort the content by clicking on a column header,
works fine.

Is there a way to sort by multiple columns ?
The sort api of Container.Sortable allows this, but it there a existing UI functionality to use this from a table ?

André

You can use Table’s sort method:

table.sort(new String[] { "propertyId1", "propertyId2" }, new boolean[]
 { true, true });

Hello Henri,

yes, I know that I can use that method.
But has the Table component a way to let the user sort by multiple columns (For example SHIFT+CLICK on the additional sort columns) ?

Looking at what the client side of the table sends to the server side on a header click, we can see that it sends to bits of information. “sortcolumn” is a name of a property in the container and “sortascending” is the direction as a boolean. These are stored as fields on the server side so the earlier sorting will be lost at that point. I afraid that some shift click etc. for multiple column sorting is not possible from the table itself.

What you can do, however, is build a separate layout above the table that gathers the sorting preferences from the user, and calls sort(Object propertyId, boolean
ascending) based on that input. You’d need a select field for the property id and a checkbox for direction, and possible ‘+’ and ‘-’ -buttons for adding and removing properties. Maybe something similar to
Vaadin’s Tracs filtering
, for example.

Currently not - see
ticket #5386
and add comments to it if necessary.

EDIT: Note also that Table.sort() simply calls Container.Sortable.sort(), which depending on the container may leave the container sorted and apply a stable sort the next time. If your container does so (as some in-memory containers do), simply first sorting by property A and then by property B does leave the table sorted so that B is the primary sort column and A is used to sort within equal values of B.