-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
I want to use chosenbox for searching and selecting elements from some huge models (about 1 mil entries). I can't use SubModel by 3 reasons: 1. I need to set selected some elements while creating chosenbox and there is no method 'addToSelection()' in SubModel. 2. Searching in submodel with 1 mil entries by iteration over it using comparator is very slow. 3. Data sources can be different, in some cases data is being taken from databse, in other from data structures which allow to search faster than iterating over all collection.
Here is my zk fiddle with simplified example how I try to do it. It works fast in my project but here is the problem: 1. I type in some value 2. It itriggers onSearching event 3. Chosenbox shows me available results 4. Typed in value erases from chosenbox
I want to keep that value so user can continue typing.
I also tried the same approach on a Combobox and it works fine, typed in value is not being erased when model changes.
Despite your 3 reasons:
Here an example using a custom ListModel/ListSubModel implementation ComboboxHugeModel
.
This model doesn't store any data besides the selection (performed by AbstractListModel). It delegates calls to getSubModel() to the outer VM where you can implement your DB query logic based on what the user has typed - this allows reuse in multiple views with varying queries.
There is no need to replace the model since it's always empty and computes the search results on-the-fly (of course you could add some caching logic here but that's often already done by your persistence implementation, e.g. hibernate - so I ignored that for this example).
https://zkfiddle.org/sample/1hmt127/4-chosenbox-with-huge-model
I hope this is useful.
Asked: 2021-10-28 21:00:52 +0800
Seen: 6 times
Last updated: Oct 29 '21
bug with intboxes on mobile devices
zk keikai-how to add custom button/label to formulabar?
zk-keikai- update multiple cells parallel at same time asynchronously
zk-keikai-How to auto fit column width based on text
zk-keikai-ClipboardPateEvent-called twice
Reference a spring bean from VariableResolver