I want to code a method where I pass a textfield (filterField), data from a tableview (data) and tableview (table) in order to filter all the table data, checking each time a key is released in the textfield, if the string typed is contained in any cell of the table.
This method is to be generic and used for different type of tables with different column headers.
To do so I´m using the following code:
public void addTextFilter(ObservableList<List<Object>> allData,
JFXTextField filterField, TableView<List<Object>> table) {
FilteredList<List<Object>> filteredData = new FilteredList<>(allData, p -> true);
filterField.setOnKeyReleased(e ->
{
filteredData.setPredicate(p ->
{
if (filterField.getText() == null || filterField.getText().isEmpty()){
return true;
}else {
return p.contains(filterField.getText());
}
});
});
SortedList<List<Object>> sortedData = new SortedList<>(filteredData);
sortedData.comparatorProperty().bind(table.comparatorProperty());
table.setItems(sortedData);
}
This code only returns the values when the string in the textfield matches exactly the value of any cell in the table.
I would need it to return any cell of the table that contains the string typed in it while typing, even if the cell contains more characters. Something similar to this: JavaFX 8 TableView Sorting and Filtering
I would also need it to return values not depending on lowercase or uppercase values.