Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
column sort only on first out of 8 columns?
I'm displaying some data from a mysql database using Hibernate, and setting as the table's datasource a subclass of BeanItemContainer. The problem is that only the first incoming column from the database gets the sort functionality when i click on the header. I'm attaching the code below.
What are the prerequisites for a table to be able to sort each column? What is causing this?
If I remember correctly BeanItemContainer allows sorting of all properties with a type that is assignable to Comparable. So if you are using "int" in your bean you might consider using Integer instead to make integer fields sortable.
If you want to override the behavior you need to override BeanItemContainer.getSortableContainerPropertyIds() to return more than the properties that are assignable from Comparable.
Additionally you need to use another itemSorter for the container. The DefaultItemSorter uses DefaultPropertyValueComparator, which assumes all propertys are assignable to Comparable.
Ok, how do i stop sort for a single column now? :grin: It's a Date and it doesn't fall out of the Comparable cathegory no matter what i do.
What kind of Date are you using?
java.util.Date is comparable for instance.
The Date column was the only one sorting, that has been answered, now they all sort. Now i want to stop sorting exactly for the Date column because it's dd/mm/yyyy and it doesn't sort properly until i get some work done.
In other words, i need an in-Comparable Date:grin: ...or an off switch for that column.
P.S. Guess i'll have to fiddle with the comparator.