12

I'm loading 1000 records to a bootstrap select dropdownlist. It takes about 2 seconds in Chrome but takes 30 seconds in IE 9. Also, cancel or x out the bootstrap modal in IE takes 10+s too. The API call is ok but the rendering is so slow; Could some one give me some direction?

So I'm loading a list of customers and setting the selected. Here is the code.

    var customerPicker = $('#customer-picker');
    API.getCustomers().then(function (result) {
        loadDropdown(customerPicker, result.customers); 

        // set the selected to current customer; it takes 10s in IE
        customerPicker.val(currentCustomerId).selectpicker('refresh'); 

        // it takes about 10s in IE too. selector is the bs modal div
        $(selector).css('z-index', '1060').modal('show'); 
    }).catch(function (errorMessage) {
        ToastManager.showError(errorMessage || 'An error occurred while loading customer list. Please try again.');
    });

    function loadDropdown($div, arr) {
        var options = '';
        $.each(arr, function (i, item) {
            options = options + '<option value="' + item.Value + '">' + item.Text + '</option>';
        });
        $div.html(options);
    }

enter image description here

Quentin
  • 1,310
  • 18
  • 30
  • Have you tried `$div.append(' – Robin Mackenzie Dec 15 '16 at 22:32
  • @RobinMackenzie yeah I tried without luck. – Quentin Dec 15 '16 at 22:40
  • 1
    What version of jQuery are you using? It's quite possible that you may solve this by trying different jQuery releases since both functions you mentioned deal directly with js. – Serg Chernata Jan 17 '17 at 12:07
  • i am using the 1.11.3 version for jQuery. – Purvesh Desai Jan 17 '17 at 12:16
  • Also, using latest version of Selectpicker 1.12.1 – Purvesh Desai Jan 17 '17 at 12:24
  • 1
    A quick search on the issues for this repo on github shows that performance for large datasets is lacking: https://github.com/silviomoreto/bootstrap-select/issues May want to look into a different solution for handling the number of options you're rendering. – Tim Lewis Jan 19 '17 at 16:33
  • 1
    Try lazy loading. Load data in chunks. – Juned Lanja Jan 23 '17 at 05:15
  • 1
    Using a select to present 1000 records doesn't usually make for the best UI to the user. Having to scroll through that many records isn't usually welcome. Can you consider something like an autocomplete dropdown so as the user starts to type the name then you filter and display all matching records? – David Brown Jan 23 '17 at 12:51

4 Answers4

2

Have you tried setting the innerHTML inside of the loop;

 $div[0].innerHTML += '<option value="' + item.Value + '">' + item.Text + '</option>';

Instead of this at the end.;

 $div.html(options);
Liam
  • 114
  • 5
1

Perhaps you wish to consider a serialization library to handle with how many records it's really loading at once. Clusterize.js is a very well made one, and only allows the browser to render currently being viewed by the client. It shows anywhere up to 100,000+ records to be handled in this manner.

https://clusterize.js.org/

Joshua
  • 648
  • 7
  • 18
0

you can use :
Select2 kind of utility loading 1000+ record is not a good idea.
https://select2.github.io/examples.html

Mantu Nigam
  • 3,690
  • 7
  • 24
  • 41
0

Jquery can experience a performance hit in older browsers. Here's a solution similar to what you're experiencing. $.each() is already pretty slow compared to native JS.

Community
  • 1
  • 1
ndkline
  • 1
  • 3