TableView2 that provides extended filtering options.
The table items have to be wrapped with a FilteredList.
configureForFiltering
is a convenient method that can be used for that purpose.
PopupFilter control can be used to display filtering options. This
control can be displayed via FilteredTableColumn#onFilterAction.
SouthFilter control can be placed in the south
header node.
Let's provide the underlying data model, based on a Person class.
public class Person {
private StringProperty firstName;
public void setFirstName(String value) { firstNameProperty().set(value); }
public String getFirstName() { return firstNameProperty().get(); }
public StringProperty firstNameProperty() {
if (firstName == null) firstName = new SimpleStringProperty(this, "firstName");
return firstName;
}
private StringProperty lastName;
public void setLastName(String value) { lastNameProperty().set(value); }
public String getLastName() { return lastNameProperty().get(); }
public StringProperty lastNameProperty() {
if (lastName == null) lastName = new SimpleStringProperty(this, "lastName");
return lastName;
}
}
A FilteredTableView can be created, and filled with an observable list of people, that has to be wrapped with a SortedList and a FilteredList, in order to apply sorting and filtering:
FilteredTableView<Person> table = new FilteredTableView<Person>();
ObservableList<Person> people = getPeople();
FilteredList<Person> filteredPeople = new FilteredList<>(people);
filteredPeople.predicateProperty().bind(table.predicateProperty());
SortedList<Person> sortedPeople = new SortedList<>(filteredPeople);
sortedPeople.comparatorProperty().bind(table.comparatorProperty());
table.setItems(sortedPeople);
Alternatively, configureForFiltering
can be used:
FilteredTableView<Person> table = new FilteredTableView<Person>();
ObservableList<Person> people = getPeople();
FilteredTableView.configureForFiltering(table, people);
Now we add two columns to the table:
FilteredTableColumn<Person,String> firstNameCol = new FilteredTableColumn<>("First Name");
firstNameCol.setCellValueFactory(p -> p.getValue().firstNameProperty());
FilteredTableColumn<Person,String> lastNameCol = new FilteredTableColumn<>("Last Name");
lastNameCol.setCellValueFactory(p -> p.getValue().lastNameProperty());
table.getColumns().setAll(firstNameCol, lastNameCol);
A cell factory that allows commit on focus lost can be set:
firstName.setCellFactory(TextField2TableCell.forTableColumn());
We can fix some row and columns, and also show the row header:
table.getFixedColumns().setAll(firstNameColumn);
table.getFixedRows().setAll(0, 1, 2);
table.setRowHeaderVisible(true);
A popup filter editor can be easily added to a column header:
PopupFilter<Person, String> popupFirstNameFilter = new PopupStringFilter<>(firstName);
firstName.setOnFilterAction(e -> popupFirstNameFilter.showPopup());
Alternatively, a south filter editor can be added to the south node:
SouthFilter<Person, String> editorFirstNameFilter = new SouthFilter<>(firstName, String.class);
firstName.setSouthNode(editorFirstNameFilter);
| Modifier and Type | Field and Description |
|---|---|
| private ObservableList | backingList
Original observable list, before it is wrapped into a FilteredList and SortedList. |
| public static final Callback | DEFAULT_FILTER_POLICY
The default |
| private ObjectProperty | filterPolicy
The filter policy specifies how filtering in this FilteredTableView should be performed. |
| private ObjectProperty | onFilter
Called when there's a request to filter the control. |
| private ReadOnlyObjectWrapper | predicate
The predicate property is a read-only property that is representative of the current state of the filter list. |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static < The type of the objects contained within the FilteredTableView items list S> void | configureForFiltering(FilteredTableView<S>
The FilteredTableView tableView, ObservableList<S> The items)items listConvenient method to set the items for the |
| public void | |
| public final ObjectProperty | |
| pack-priv ObservableList | Returns: The originalObservableListReturns the original observable list, before it is wrapped into a
|
| public final Callback | |
| public final EventHandler | |
| public final Predicate | |
| public final ObjectProperty | |
| public final ReadOnlyObjectProperty | |
| private ReadOnlyObjectWrapper | |
| private void | |
| public void | |
| public void | setBackingList(ObservableList<S>
The original backingList)ObservableListSets the original observable list, before it is wrapped into a
|
| public final void | |
| public final void | |
| private void |
| backingList | back to summary |
|---|---|
| private ObservableList<S> backingList Original observable list, before it is wrapped into a FilteredList and SortedList. It is required to track the changes in the underlying data model (backend, or cell-editing) | |
| DEFAULT_FILTER_POLICY | back to summary |
|---|---|
| public static final Callback<FilteredTableView<S>, Boolean> DEFAULT_FILTER_POLICY The default | |
| filterPolicy | back to summary |
|---|---|
| private ObjectProperty<Callback<TableView<S>, Boolean>> filterPolicy The filter policy specifies how filtering in this FilteredTableView should be performed.
For example, a basic filter policy may just call
FilteredTableView ships with a It is recommended that rather than override the | |
| onFilter | back to summary |
|---|---|
| private ObjectProperty<EventHandler<FilterEvent<TableView<S>>>> onFilter Called when there's a request to filter the control. | |
| predicate | back to summary |
|---|---|
| private ReadOnlyObjectWrapper<Predicate<S>> predicate The predicate property is a read-only property that is representative of the current state of the filter list. The filter list contains the columns that have been added to it either programmatically or via a user clicking on the headers themselves. | |
| FilteredTableView | back to summary |
|---|---|
| public FilteredTableView() Creates a FilteredTableView control. | |
| FilteredTableView | back to summary |
|---|---|
| public FilteredTableView(ObservableList<S> items) | |
| configureForFiltering | back to summary |
|---|---|
| public static <S> void configureForFiltering(FilteredTableView<S> tableView, ObservableList<S> items) Convenient method to set the items for the
| |
| filter | back to summary |
|---|---|
| public void filter() The filter method forces the TableView to re-run its filtering algorithm. More
often than not it is not necessary to call this method directly, as it is
automatically called when the
| |
| filterPolicyProperty | back to summary |
|---|---|
public final ObjectProperty
| |
| getBackingList | back to summary |
|---|---|
| pack-priv ObservableList Returns the original observable list, before it is wrapped into a
| |
| getFilterPolicy | back to summary |
|---|---|
public final Callback
| |
| getOnFilter | back to summary |
|---|---|
| public final EventHandler | |
| getPredicate | back to summary |
|---|---|
| public final Predicate | |
| onFilterProperty | back to summary |
|---|---|
| public final ObjectProperty | |
| predicateProperty | back to summary |
|---|---|
| public final ReadOnlyObjectProperty | |
| predicatePropertyImpl | back to summary |
|---|---|
| private ReadOnlyObjectWrapper | |
| resetColumnsFilter | back to summary |
|---|---|
| private void resetColumnsFilter() | |
| resetFilter | back to summary |
|---|---|
| public void resetFilter() Resets all the filters applied, to both tableView and filtered columns | |
| setBackingList | back to summary |
|---|---|
| public void setBackingList(ObservableList<S> backingList) Sets the original observable list, before it is wrapped into a
| |
| setFilterPolicy | back to summary |
|---|---|
| public final void setFilterPolicy(Callback<TableView<S>, Boolean> callback) | |
| setOnFilter | back to summary |
|---|---|
| public final void setOnFilter(EventHandler<FilterEvent<TableView<S>>> value) | |
| setPredicate | back to summary |
|---|---|
| private void setPredicate(Predicate<S> value) | |