0

Huge model for chosenbox onSearching

asked 2021-10-28 21:00:52 +0800

pavelEW gravatar image pavelEW
55 4

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.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-10-29 12:36:45 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2021-10-29 12:43:42 +0800

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.

link publish delete flag offensive edit

Comments

I had to update the model otherwise it doesn't allow add items to selection, but this approach works really great. Thank you!

pavelEW ( 2021-11-08 16:46:50 +0800 )edit

thanks for getting back, good to know the example was helpful

cor3000 ( 2021-11-08 18:52:56 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2021-10-28 21:00:52 +0800

Seen: 6 times

Last updated: Oct 29 '21

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More