I need to implement a filter in javafx tableview with huge data (around 100,000 ),
I have tried this tutorial. It works but filtering is really slow as compared to swing sorting and filtering, code.
Can anyone help me to increase speed.
What is happening right now is as I type textproperty change fire up and filterdata but it is slow, I need something which shows filter result with typing quickly as happening in swing.
thanks in advance.
p.s I have also looked at this.
We can filter TableView content in two main ways – manually, or by using the FilteredList class JavaFX provides. In either case, we can update our search criteria by placing a ChangeListener on the search box TextField. This way, each time the user changes their search, the TableView is updated automatically.
You may use FilteredList
ObservableList<YourObjectClass> actualList = ...;
FilteredList<YourObjectClass> filteredList = new FilteredList<>(actualList);
TableView table = ...;
table.setItems(filteredList);
// to filter
filteredList.setPredicate(
new Predicate<YourObjectClass>(){
public boolean test(YourObjectClass t){
return false; // or true
}
}
);
as fast as swing, (maybe faster then swing... ). (I tested with 100000 rows)
You can use the following code. It works fine for me..
ObservableList data = table.getItems();
textfield.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
if (oldValue != null && (newValue.length() < oldValue.length())) {
table.setItems(data);
}
String value = newValue.toLowerCase();
ObservableList<T> subentries = FXCollections.observableArrayList();
long count = table.getColumns().stream().count();
for (int i = 0; i < table.getItems().size(); i++) {
for (int j = 0; j < count; j++) {
String entry = "" + table.getColumns().get(j).getCellData(i);
if (entry.toLowerCase().contains(value)) {
subentries.add(table.getItems().get(i));
break;
}
}
}
table.setItems(subentries);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With