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/
- 1The link you gave is the easiest and most efficient way I could think of for implementing what you want. What's your problem with it?omgBob– omgBob2015-03-06 06:50:36 +00:00Commented Mar 6, 2015 at 6:50
- If I have thousand rows with different data and I want to view just few then this process seems to be tedious to me. I want exactly the same feature of filtering as provided by microsoft excel.Harshita Sethi– Harshita Sethi2015-03-06 09:54:39 +00:00Commented Mar 6, 2015 at 9:54
- 2Why can't you use the methods in that link to create a filter similar to the one in Excel? You probably need to create and post a simple example to show what you have tried.James_D– James_D2015-03-06 13:25:48 +00:00Commented Mar 6, 2015 at 13:25
- Actually what i need to ask that is there a direct way inbuilt in javafx like there is tablemenubutton, sorting functions. Similarly in javafx, in there any inbuilt functionality for filtering?Harshita Sethi– Harshita Sethi2015-03-10 05:54:05 +00:00Commented Mar 10, 2015 at 5:54
Add a comment |
2 Answers
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:
Comments
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); 3 Comments
Baum mit Augen
Please don't just post some tool or library as an answer. At least demonstrate how it solves the problem in the answer itself.
Baum mit Augen
Looks better now, thanks. (Not my downvote btw, I lack domain knowledge to vote on this.)
maimArt
Thank you for your feedback. Hope the downvoter can also give me some feedback to improve my behaviour or code.