-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage question: attaching an array and have option elements lazily created? #2081
Comments
While the groundwork is laid for dynamic options, there is still some work needed in order to get this to work smoothly. Something like this might point you in the right direction: $('#number').on('loaded.bs.select', function () {
var Selectpicker = $('#number').data('selectpicker');
Selectpicker.$menuInner.on('scroll', function () {
var scrollTop = Selectpicker.selectpicker.view.scrollTop;
// if within 100px of the bottom of the menu, load more options
if ($(this)[0].scrollHeight - Selectpicker.sizeInfo.menuInnerHeight - scrollTop < 100) {
$('#number').append(newOptions);
$('#number').selectpicker('refresh');
}
});
}); See an example here: https://next.plnkr.co/edit/OAfCYwHVHOArFAz7. |
wow thanks! - would the livesearch work on data not yet in an option element? I looked at the code and this did not seem to be case on a quick look |
btw - I had forgotten about jquery ui's autocomplete, where you can pass it the array and it just adds things as necessary based on what you typed |
It's not yet possible to use live search to search for options not yet in the array. You'll want to follow #1305. How many options would there potentially be? With bootstrap-select v1.13.2 and the virtualScroll option, thousands of options render much faster than in previous versions. |
it seems like first just creating > 10,000 option elements alone is the bottleneck, before the selectpicker is even instantiated. jquery's autocomplete is much faster (since it does the lazy load thing from the array you give it) and works, but you don't get a nice look at what's there before you decide to enter a particular search term... which might be incompatible with performance in the first place... |
Check out https://github.com/truckingsim/Ajax-Bootstrap-Select in the meantime. |
hey thanks - will check it out! In my case, I'm not getting data via ajax btw. |
I haven't looked at that plugin too closely, but I think you should be able to simulate an Ajax request and use local data instead. |
could also try lazy-loading #2187 |
Please 👍 and follow #899. |
This may be trivial.
I have a large array and want the select to create the option elements only as necessary - me creating them all up front is too slow. I saw a few hints that this might be possible with bootstrap-select as it is but I haven't seen that it is fully possible....
thanks!
The text was updated successfully, but these errors were encountered: