Reputation: 8363
When I click on a table column in a TableView
, it will alternate from ascending
, descending
and default
(no arrow). How do I make it toggle between just ascending
and descending
?
Upvotes: 2
Views: 794
Reputation: 8363
I meddled with many properties from the TableView
and TableColumn
and I found my own solution. It is definitely not elegant, and is also not thread-safe, but at least it works, and it's simple.
public static final <T> void disableColumnUnsortedOnClick(TableView<T> tableView)
{
tableView.getSortOrder().addListener(new ListChangeListener<TableColumn<T, ?>>()
{
@Override
public void onChanged(
javafx.collections.ListChangeListener.Change<? extends TableColumn<T, ?>> c)
{
while (c.next())
{
if (c.wasRemoved() && c.getRemovedSize() == 1 && !c.wasAdded())
{
final TableColumn<T, ?> removedColumn = c.getRemoved().get(0);
removedColumn.getTableView().getSortOrder().add(removedColumn);
removedColumn.setSortType(SortType.ASCENDING);
}
}
}
});
}
Upvotes: 2