Reputation: 2125
Is there a way to filter table columns data as there is a way in excel to filter. Filtering manually require a very long code if data is huge. So trying to find an easy way. Please suggest something. I went through the following link for the same but need an easier and efficient approach. http://code.makery.ch/blog/javafx-8-tableview-sorting-filtering/
Upvotes: 2
Views: 5230
Reputation: 399
I wrote an extension for that use case:
https://github.com/maimArt/TableFilterFX
The implementation of the filter is quite easy. You wrap your TableView with the TableFilter and add the columns that should be filterd by tableFilter.filterColumn(TableColumn column)
1 Build your TableView like usual by code or fxmlTableView<Pojo> table = new TableView<>();
table.getItems().addAll(pojoList);
TableColumn<Pojo, String> columnA = new TableColumn<>("ColA");
TableColumn<Pojo, String> columnB = new TableColumn<>("ColB");
table.getColumns().add(columnA);
table.getColumns().add(columnB);
2 After that apply the filter
TableFilter<Pojo> tableFilter = new TableFilter<>(table);
tableFilter.filterColumn(columnA);
tableFilter.filterColumn(columnB);
Upvotes: 3
Reputation: 520
There's no built-in filter capability for TableViews like Excel.
I've written a library that provides the GUI filters, but you'll still need to programmatically apply the results to filter your dataset:
https://code.google.com/p/javafx-filterable-table-columns/
https://github.com/jhsheets/javafx-filterable-table-columns
Upvotes: 4