Way to filter/search ListView contents
-
I looking for an elegant way to filter ListView contents by text in TextInput (as in Android contacts).
My current suggestions:
- Changing visible property of delegate.
That should have good perfomance, but ListView reserves space for empty delegates, and user see empty fields, need to hide non-visible delegates somehow. - Using two ListModel instances. First instance stores full set of data, second stores filtered subset, view connected to second. That method have high memory and processor time costs: each time when filter expression changes we need to clear second model then fill it again with new subset of data.
- Changing visible property of delegate.
-
Hi,
This is a job for QSortFilterProxyModel. Attach your ListView to the proxy model, not the original model.
-
Yeah, QSortFilterProxyModel exactly for that task, but currently i sticked to QML ListModel, don't know maybe its possible to connect QSortFilterProxyModel to ListModel.
Maybe someone have suggestions on how implement that with QML/JS?
-
Sorry, my brain wasn't working properly -- I completely missed the fact that you're working in QML.
Anyway, does this help?: http://kunalmaemo.blogspot.com.au/2013/04/creating-qml-listview-with-search.html
(I Googled "QML filter model")