Hello,
In Grid component, when you set a custom comparator on a column, I expect the reversed() method of my comparator to be used when I select reversed order in the header.
However, the reversed order is generated by inverting the ascending order of my comparator, not by using the reversed method.
Digging into the code, we can see that int the class Column (Vaadin 24.8.8):
public Column<T> setComparator(Comparator<T> comparator) {
Objects.requireNonNull(comparator, "Comparator must not be null");
this.setSortable(true);
this.comparator = comparator::compare;
return this;
}
Knowing that this.comparator is an instance of SerializableComparator, an internal class, the line this.comparator = comparator::compare; create a new instance of SerializableComparator based on the compare(T,T) method of the given comparator (here my custom comparator).
This prevents the method reversed() to be used in the subsequent uses of this.comparator.
Specially in:
public SerializableComparator<T> getComparator(SortDirection sortDirection) {
Objects.requireNonNull(comparator, "No comparator defined for sorted column.");
setSortable(true);
boolean reverse = sortDirection != SortDirection.ASCENDING;
return reverse ? comparator.reversed()::compare : comparator;
}
I would like to use my reversed method instead of the built-in one.