nobleclem / jQuery-MultiSelect

Turn a multiselect list into a nice and easy to use list with checkboxes.
https://springstubbe.us/projects/jquery-multiselect/
MIT License
289 stars 216 forks source link

ajax on search #179

Closed sali-karwasolutions closed 2 years ago

sali-karwasolutions commented 3 years ago

I want to use multi-select with additional feature of ajax search.

I would like to search a result from any given url and load that as multi-select options.

I have search for option for similar functionality but couldn't find answer, Please suggest if I am doing it right.

$.ajax({ type: "Get", url: ${searchUrl}${text}, dataType: "json", success: function (orgUnits) { orgUnits.forEach(function (orgUnit) { $(elementId).append(new Option(orgUnit.name, orgUnit.id)); }); }, error: function (e) { console.log(e); } });

nobleclem commented 3 years ago

Look at the example Dynamically Populate List on the Demo Page.

Basically you will get your options from your ajax call. Then use the loadOptions method to populate the select list.

Alternatively you can manually add options to the select list and then call the reload method $('select[multiple]').multiselect('reload');.

Oh also check out issue #3

sali-karwasolutions commented 3 years ago

thank you that worked like a charm, some of the examples referred to reload as refresh which I think is not a method which caused by code not working as intended.