tornadofx
tornadofx copied to clipboard
SortedFilteredList does not set predicate field with initialPredicate
If the initialPredicate
constructor parameter of SortedFilteredList
is set, the predicate
field does not get set. This means that refilter()
does not work as expected.
fun test() {
val list = SortedFilteredList(listOf(1).toObservable(), { myPredicate(it) })
list.refilter()
}
fun myPredicate(value: Int) {
// Expect this to be called twice, but is only called once
return value > 3
}
but this example does not understand anything, you call the function - therefore, it must be called when it calls the lambda (predicate), and in this case the order is not important
listOf(1).toObservable() == observableListOf(1)
work
class V : View() {
val items = observableListOf(1, 2, 10)
val list = SortedFilteredList(items, { print("Sorter"); myPredicate(it) }).apply {
refilter()
}
// val filter = FilteredList(items, Predicate { print("Filter"); myPredicate(it) })
override val root = vbox {
listview(list) {
cellFormat { text = it.toString() }
}
// listview(filter) {
// cellFormat { text = it.toString() }
// }
}
private var callPredicate = 0
fun myPredicate(value: Int): Boolean {
// Expect this to be called twice, but is only called once
println("call: ${callPredicate++}")
return value > 3
}
}```
I apologize, did not immediately understand what was needed, but the repeated filter did not invoke. @edvin
I think, if I understand this, that I came to the same situation when first trying to use SortedFilteredList with a TableView.
It seemed kind of strange having to define the same predicate twice, once for the initial conditions, then once to have it filter the table when some value changes (using filterWhen), when I would have guessed that simply calling refilter() would filter the table again with the initially supplied predicate.