Remove TableView entries when status change

后端 未结 1 1187
北荒
北荒 2020-12-07 05:30

I am having a problem trying to figure out how to make a TableView show the correct data based on each entry response status. I thought FilteredList

相关标签:
1条回答
  • 2020-12-07 05:49

    A FilteredList will update whenever it's Predicate changes or whenever it detects a change in the source ObservableList. The type of event you want to fire is an update event. This event signifies one or more elements have been updated (e.g. when a property changes). In order to do this you have to construct the ObservableList with the appropriate factory method: FXCollections.observableArrayList(Callback).

    This factory method takes a Callback that accepts an element of the ObservableList and returns an Observable[]. The Observables in the array will be listened to for invalidation events and, when detected, will cause the ObservableList to fire an update change.

    From looking at your code it seems1 like the Model class has a status property. If you want to fire updates when the status changes you should use:

    ObservableList<Model> masterData = FXCollections.observableArrayList<>(model ->
            new Observable[]{model.statusProperty()});
    

    You can add more Observables to the array if you wish for updates to be fired for more than just changes to the status property.

    Now when the status property changes the FilteredList will notice and filter the element(s) if needed.


    1. You hadn't posted the Model class when I wrote this answer. However, I manage to "reverse engineer" it from the available code and tested it using the Callback extractor. The elements were removed from the FilteredList, and thus the TableView, when the status changed from PENDING to whatever the new status ended up being.

    0 讨论(0)
提交回复
热议问题