bootstrap-select icon indicating copy to clipboard operation
bootstrap-select copied to clipboard

Problem when you have many data

Open victorrodrigues opened this issue 13 years ago • 7 comments

Hi, @silviomoreto,

There is a problem when we get lots of data via json, and construct the select. Here is a example:

I have the first select with States, and second the combo with Cities of this particular State.

$('#select_state').change(function(){
    $.ajax({
        dataType: "json",
        url: '/states/'+$(this).val()+'/cities.json',
        success: function (data) {
            $("#select_city").empty();
            $.each(data, function(i,item){
                $("<option value=\"" + item.id + "\">" + item.name + "</option>").appendTo('#select_city');
            });
        }
    });
});

When i click in "São Paulo" state, for example, which has 645 cities, browser crashes. There is some hack to solve this problem?

Thx :)

victorrodrigues avatar Apr 09 '13 20:04 victorrodrigues

We will check it out, but can you provide more info? Like.. what kind of problem happens? The #select_city doesnt loads? Just an internal error occurs?

silviomoreto avatar Apr 10 '13 08:04 silviomoreto

No errors is shown. the #select_city doesn't load, and after a few seconds waiting, the tab browser crash. Here is a Gist of the json with all 645 cities. So it's 645 objects to create all the elements, refresh, and so on...

I think this is too heavy to do all this stuff on every element that was added to the "original" select tag. I tried with a small State (with 19 cities) and it load slowly, but it dont crash the tab.

Im using Google Chrome Version 26.0.1410.63 and Macbook Pro 13'' Core i7

victorrodrigues avatar Apr 10 '13 15:04 victorrodrigues

You've tried it without loading bootstrap-select and it works fine?

caseyjhol avatar Apr 11 '13 19:04 caseyjhol

Yes. Removing the bootstrap-select and using with native select box, was super fast.

victorrodrigues avatar Apr 11 '13 20:04 victorrodrigues

@victorrodrigues, Not to say that they shouldn't fix the problem with Bootstrap-select if there's an issue but if you have a list of 645 items maybe a select it's not the best thing to use. You should probably look into the Bootstrap's Typeahead and use something like that instead...

t3chn0r avatar Apr 11 '13 21:04 t3chn0r

I suspect it's because the plugin re renders when a dom element is inserted.

So for every iteration of your 600 odd items, it re builds the list, which in turn loops the same list of items.

Can you not construct the option elements and then insert the lot in one go, rather than inserting as you go?

mattbryson avatar Apr 12 '13 03:04 mattbryson

@t3chn0r and @mattbryson are right.

Perhaps you should create a new select element instead of just updating that old one. This should at least improve the performance. If not let us know.

silviomoreto avatar Apr 12 '13 09:04 silviomoreto