I have a javafx TableView and I want to know when the sort order of a column changes. I added a listener to the getSortOrder
method. However, it only fires when I sort ascending, and never when I sort descending.
To test this I used this example code
Does anyone have an idea why this doesn't fire? Do I need to add sth else?
The data in the table is in a SortedList
and I added the listener as follows:
personTable.getSortOrder().addListener(this::onColumnSortOrderChanged);
private void onColumnSortOrderChanged(ListChangeListener.Change<? extends TableColumn<Person, ?>> change) {
boolean changed = false;
while (change.next()) {
changed = true;
}
if (changed) {
if (change.getList().isEmpty()) {
System.out.println("observable is empty");
} else {
TableColumn<Person, ?> column = change.getList().get(0);
System.out.println("Sorted: " + column.getText() + " sort type " + column.getSortType());
}
}
}