Javafx TableView sorting uses ascending order first when clicking on a column header, then descending order on second click. I have a table with sports team data with columns for wins, losses etc. Wins should be sorted by default in descending order and losses in ascending order so the best team in each category is always on top when clicking once on a header.
I have tried sortType="DESCENDING"
in the fxml file and setSortType(TableColumn.SortType.DESCENDING)
in code with no effect.
In my use case the secondary sorting option is more of a hinderance. The solution I came up with only allows sorting a column in one way, clicking the header toggles between sorted and not used for sorting.
Only allowing descending sorting is simpler and only requires a listener to the table sortOrder. Only allowing ascending sorting however requires adding a listener to the column sortTypeProperty and for multisorting using the shift-key to work correctly the correct sorting must also be forced in the table sortOrder listener.