Top Description Fields Constructors Methods
org.controlsfx.control.tableview2

public Class FilteredTableView<S>

extends TableView2<S>
Class Inheritance
Type Parameters
<S>
The type of the objects contained within the FilteredTableView items list.
Imports
impl.org.controlsfx.tableview2.FilteredColumnPredicate, javafx.beans.property.ObjectProperty, .ObjectPropertyBase, .ReadOnlyObjectProperty, .ReadOnlyObjectWrapper, .SimpleObjectProperty, javafx.collections.ObservableList, javafx.collections.transformation.FilteredList, .SortedList, javafx.event.EventHandler, .EventType, javafx.scene.control.TableView, javafx.util.Callback, org.controlsfx.control.tableview2.event.FilterEvent, org.controlsfx.control.tableview2.filter.filtereditor.FilterEditor, .SouthFilter, org.controlsfx.control.tableview2.filter.popupfilter.PopupFilter, java.util.Objects, java.util.function.Predicate, java.util.logging.Level, .Logger

A subclass of 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.

Features


A filter icon is displayed in the column's header, and its color will show if the column has a predicate applied or not.
A PopupFilter control can be used to display filtering options. This control can be displayed via FilteredTableColumn#onFilterAction.
Alternatively, a SouthFilter control can be placed in the south header node.

Sample

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);

Field Summary

Modifier and TypeField and Description
private ObservableList<S>
backingList

Original observable list, before it is wrapped into a FilteredList and SortedList.

public static final Callback<FilteredTableView<S>, Boolean>
DEFAULT_FILTER_POLICY

The default filter policy that this FilteredTableView will use if no other policy is specified.

private ObjectProperty<Callback<TableView<S>, Boolean>>
filterPolicy

The filter policy specifies how filtering in this FilteredTableView should be performed.

private ObjectProperty<EventHandler<FilterEvent<TableView<S>>>>
onFilter

Called when there's a request to filter the control.

private ReadOnlyObjectWrapper<Predicate<S>>
predicate

The predicate property is a read-only property that is representative of the current state of the filter list.

Constructor Summary

AccessConstructor and Description
public
FilteredTableView()

Creates a FilteredTableView control.

public

Method Summary

Modifier and TypeMethod 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> items)

Convenient method to set the items for the FilteredTableView by wrapping them with a FilteredList and a SortedList, that are also bound properly to the table's predicateProperty() and TableView#comparatorProperty().

public void
filter()

The filter method forces the TableView to re-run its filtering algorithm.

public final ObjectProperty<Callback<TableView<S>, Boolean>>
pack-priv ObservableList<S>

Returns:

The original ObservableList
getBackingList
()

Returns the original observable list, before it is wrapped into a FilteredList and a SortedList.

public final Callback<TableView<S>, Boolean>
public final EventHandler<FilterEvent<TableView<S>>>
public final Predicate<S>
public final ObjectProperty<EventHandler<FilterEvent<TableView<S>>>>
public final ReadOnlyObjectProperty<Predicate<S>>
private ReadOnlyObjectWrapper<Predicate<S>>
private void
public void
resetFilter()

Resets all the filters applied, to both tableView and filtered columns

public void
setBackingList(ObservableList<S>
The original ObservableList
backingList
)

Sets the original observable list, before it is wrapped into a FilteredList and a SortedList.

public final void
public final void
private void
Inherited from org.controlsfx.control.tableview2.TableView2:
areRowsFixablecolumnFixingEnabledPropertycreateDefaultSkingetColumnSpangetFixedColumnsgetFixedRowsgetRowHeadergetRowHeaderContextMenuFactorygetRowHeaderWidthgetRowSpangetSpanTypegetUserAgentStylesheetisColumnFixableisColumnFixingEnabledisRowFixableisRowFixingEnabledisRowHeaderVisibleisSouthHeaderBlendedrowFixingEnabledPropertyrowHeaderContextMenuFactoryPropertyrowHeaderPropertyrowHeaderVisiblePropertyrowHeaderWidthPropertysetColumnFixingEnabledsetRowFixingEnabledsetRowHeadersetRowHeaderContextMenuFactorysetRowHeaderVisiblesetRowHeaderWidthsetSouthHeaderBlendedsortsouthHeaderBlendedProperty

Field Detail

backingListback 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_POLICYback to summary
public static final Callback<FilteredTableView<S>, Boolean> DEFAULT_FILTER_POLICY

The default filter policy that this FilteredTableView will use if no other policy is specified. The filter policy is a simple Callback that accepts a FilteredTableView as the sole argument and expects a Boolean response representing whether the filter succeeded (true) or not (false).

filterPolicyback 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 FXCollections.filter(tableView.getItems()), whereas a more advanced filter policy may call to a database to perform the necessary filtering on the server-side.

FilteredTableView ships with a default filter policy that does precisely as mentioned above: it simply attempts to filter the items list in-place.

It is recommended that rather than override the filter method that a different filter policy be provided instead.

onFilterback to summary
private ObjectProperty<EventHandler<FilterEvent<TableView<S>>>> onFilter

Called when there's a request to filter the control.

predicateback 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.

Constructor Detail

FilteredTableViewback to summary
public FilteredTableView()

Creates a FilteredTableView control.

FilteredTableViewback to summary
public FilteredTableView(ObservableList<S> items)

Method Detail

configureForFilteringback to summary
public static <S> void configureForFiltering(FilteredTableView<S> tableView, ObservableList<S> items)

Convenient method to set the items for the FilteredTableView by wrapping them with a FilteredList and a SortedList, that are also bound properly to the table's predicateProperty() and TableView#comparatorProperty().

Parameters
<S>
The type of the objects contained within the FilteredTableView items list
tableView:FilteredTableView<S>

The FilteredTableView

items:ObservableList<S>

The items list

filterback 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 filter policy, or the state of the FilteredTableColumn filter predicate changes. In other words, this method should only be called directly when something external changes and a filter is required.

filterPolicyPropertyback to summary
public final ObjectProperty<Callback<TableView<S>, Boolean>> filterPolicyProperty()
Annotations
@SuppressWarnings:unchecked
getBackingListback to summary
pack-priv ObservableList<S> getBackingList()

Returns the original observable list, before it is wrapped into a FilteredList and a SortedList.

Returns:ObservableList<S>

The original ObservableList

getFilterPolicyback to summary
public final Callback<TableView<S>, Boolean> getFilterPolicy()
Annotations
@SuppressWarnings:unchecked
getOnFilterback to summary
public final EventHandler<FilterEvent<TableView<S>>> getOnFilter()
getPredicateback to summary
public final Predicate<S> getPredicate()
onFilterPropertyback to summary
public final ObjectProperty<EventHandler<FilterEvent<TableView<S>>>> onFilterProperty()
predicatePropertyback to summary
public final ReadOnlyObjectProperty<Predicate<S>> predicateProperty()
predicatePropertyImplback to summary
private ReadOnlyObjectWrapper<Predicate<S>> predicatePropertyImpl()
resetColumnsFilterback to summary
private void resetColumnsFilter()
resetFilterback to summary
public void resetFilter()

Resets all the filters applied, to both tableView and filtered columns

setBackingListback to summary
public void setBackingList(ObservableList<S> backingList)

Sets the original observable list, before it is wrapped into a FilteredList and a SortedList. It is required to track the changes in the underlying data model (back-end, or cell editing)

Parameters
backingList:ObservableList<S>

The original ObservableList

See Also
configureForFiltering(FilteredTableView, ObservableList)
setFilterPolicyback to summary
public final void setFilterPolicy(Callback<TableView<S>, Boolean> callback)
setOnFilterback to summary
public final void setOnFilter(EventHandler<FilterEvent<TableView<S>>> value)
setPredicateback to summary
private void setPredicate(Predicate<S> value)