I created a form for some webapp. It features account numbers that are in and out of some group respectively presented in two listboxes, with js to allow selecting multiple numbers in a listbox and moving them to another e.g. moving accounts in and out of the group.
I move item using document fragment - i append moved options from one listbox to it and then append it to another listbox and it works quick even if the user moves 500 accounts at once.
Problem is, the number of accounts in a list box can be up to 20k, so searching for a single account is tiresome for users.
Thus I added a textbox above them and added some js to allow selecting matching account in listboxes as the user types it.
However, searching thru 20k units one by one turned out to be really slow so i added binary search to perform autoselection.
Unfortunately, binary search depends on sorting, so as soon as the user moves some accounts back and forth, moved accounts stop showing up when their name is typed cause sorting is screwed in the listboxes (items are initially sorted).
So then, to keep the listbox sorted I have two options. I either resort it after the addition by moving all the options to the array, sorting it and readding them back. This is very slow when the items are moved into a big list, even if i use documentfragment to insert them all at once again.
I can also insert them into place at once, e.g. for each moved item, search for the position that won't break searching and insert it there using insertBefore. It is slow again cause instead of inserting options to the destination listbox all at once I add them one by one.
Is there a good solution for this situation?
The best I found now is dynamically grouping asjasten inserted options into document fragments (when there are several groups where they go one after another (1,2,3,4,5 without skipped values)), searching the destination listbox for the position for each group and inserting it there.
This work for ~60% of the cases if big moves, for the remaining 40% accounts are spread thru the list and it doesn't work.
Another option is maintaining a list of moved options in an Array variable and searching main list and moved options separately but that's not really good cause when many options are moved, the 2nd search will become slow (I think so, haven't yet implemented that).
I move item using document fragment - i append moved options from one listbox to it and then append it to another listbox and it works quick even if the user moves 500 accounts at once.
Problem is, the number of accounts in a list box can be up to 20k, so searching for a single account is tiresome for users.
Thus I added a textbox above them and added some js to allow selecting matching account in listboxes as the user types it.
However, searching thru 20k units one by one turned out to be really slow so i added binary search to perform autoselection.
Unfortunately, binary search depends on sorting, so as soon as the user moves some accounts back and forth, moved accounts stop showing up when their name is typed cause sorting is screwed in the listboxes (items are initially sorted).
So then, to keep the listbox sorted I have two options. I either resort it after the addition by moving all the options to the array, sorting it and readding them back. This is very slow when the items are moved into a big list, even if i use documentfragment to insert them all at once again.
I can also insert them into place at once, e.g. for each moved item, search for the position that won't break searching and insert it there using insertBefore. It is slow again cause instead of inserting options to the destination listbox all at once I add them one by one.
Is there a good solution for this situation?
The best I found now is dynamically grouping asjasten inserted options into document fragments (when there are several groups where they go one after another (1,2,3,4,5 without skipped values)), searching the destination listbox for the position for each group and inserting it there.
This work for ~60% of the cases if big moves, for the remaining 40% accounts are spread thru the list and it doesn't work.
Another option is maintaining a list of moved options in an Array variable and searching main list and moved options separately but that's not really good cause when many options are moved, the 2nd search will become slow (I think so, haven't yet implemented that).