I’m using Vaadin (14) with server-side pagination and a custom data provider backed by JPA Criteria API.
I have done .setSortable(true) and user can click on the header to click on the sort arrow.
Previously, sorting was case-sensitive, and it was working fine.
But the user requested case-insensitive sorting. I updated my logic to use cb.lower(path) when sorting string fields:
if (String.class.equals(path.getJavaType())) {
if (order.isAscending()) {
orders.add(cb.asc(cb.lower(path)));
} else {
orders.add(cb.desc(cb.lower(path)));
}
} else {
if (order.isAscending()) {
orders.add(cb.asc(path));
} else {
orders.add(cb.desc(path));
}
}
The order looks coorect when I check the resultList, they are in the right order
Your custom DataProvider might not be recognized as “lazy loading” data provider, therefore Vaadin’s default sorting is applied on the returning list… not sure how to verify, but this might get you a good starting point to search for
If that’s the case, then it could be resolved by overriding the isInMemory method to return false since that’s what the grid looks at to determine how to sort.
I believe sort properties are used for lazy-loading dataproviders (it’s set in the Query object which you use to put together your backend database query) whereas Comparators are used for in-memory dataproviders (they can compare Java objects, so everything must be loaded into memory for them to work properly)