Reputation: 231
I have noticed that sorting by column headers in the JavaFX TableView class is turned on by default.
In my case I need to have a table view that does not allow sorting by any of the columns. Does anyone know how to do this?
Upvotes: 12
Views: 13744
Reputation: 19
/**
* Prevent a TableView from doing TableColumn sorting.
*
* @param _tableView
* @param _actionPrevent :set ON and OFF the 'Sortability' of columns.
*/
static
public < T > void preventColumnSorting( TableView< T > _tableView, boolean _actionPrevent )
{
Platform.runLater( () ->
{
_tableView.getColumns()
.forEach( column_ ->
{
column_.setSortable( ! _actionPrevent );
} );
} );
return;
}
Upvotes: -1
Reputation: 71
if you use fxml, you can also set the column unsortable in fxml:
<TableColumn sortable="false"/>
Upvotes: 3
Reputation: 4803
If you created the table columns at own instances like this:
TableColumn<Type, Type> column = new TableColumn<>("email");
then you can easily set
column.setSortable(false);
Upvotes: 33