Ajax Source from Local Array

Hello,

I have 50k array. I need to search items from local array (NOT SERVER-SIDE). How can i do this?

Example:
var 50KArray = […];

    $(".select2").select2({
        data: 50KArray, (I dont want to set here)
        minimumInputLength: 3,
        matcher: matchCustom
    });

What you want to do is not supported by the default Select2 data sources. It might be possible to “hack” a solution using the Select2 API and event handlers, but the “proper” way to do this is to specify your own custom dataAdapter that can dynamically query your 50k array without loading the whole array into the Select2.

Unfortunately there isn’t much documentation on writing your own Select2 Adapters. Your best bet is probably to look at the two dataAdapter implementations that Select2 provides–the ArrayAdapter and AjaxAdapter. You can find the code for those adapters in the Select2 GitHub repository.