Rowsorting of TableView with SortedList/FilteredList
Martin Klähn
grazertwo at gmail.com
Thu Aug 8 04:17:09 PDT 2013
Hi guys,
I'm working on a business application that makes use of TableView and I'm
working with JDK 8 build b101.
Displaying the data works like a charm. Row sorting for ordinary
ObservableLists is fine too.
Then I've set TableView.items to FilteredList and row sorting was disabled.
replacing TableView.item with SortedList does not allow row sorting as
well. Binding the comparator of SortedList to the TableView.comparator has
no effect either.
// row sorting possible
//final TableView<Integer> tableView = new
TableView<>(FXCollections.observableArrayList(2, 1, 3));
// row sorting not possible (SortedList)
// create a TableView with the sorted list set as the items it will show
// bind the sortedList comparator to the TableView comparator
//SortedList<Integer> sortedList = new
SortedList<>(FXCollections.observableArrayList(2, 1, 3));
//sortedList.comparatorProperty().bind(tableView.comparatorProperty());
//final TableView<Integer> tableView = new TableView<>(sortedList);
// row sorting not possible (FilteredList)
//FilteredList<Integer> filteredList = new
FilteredList<>(FXCollections.observableArrayList(2, 1, 3), (e) -> true);
//final TableView<Integer> tableView = new TableView<>(filteredList );
// Don't forget to define columns!
final TableColumn<Integer, Number> integerColumn = new
TableColumn<>("Integer");
final TableColumn<Integer, String> hexColumn = new TableColumn<>("Integer
Hex");
integerColumn.setCellValueFactory(javaClass -> new
SimpleLongProperty(javaClass.getValue()));
hexColumn.setCellValueFactory(javaClass -> new
SimpleStringProperty(Integer.toHexString(javaClass.getValue())));
tableView.getColumns().addAll(integerColumn, hexColumn);
Any pointers on what I'm doing wrong or where I have to adapt my
expectations.
Is it correct that row sorting in a TableView is only possible for ordinary
ObservableLists?
With Regards
Martin
More information about the openjfx-dev
mailing list