Programmaticaly add templated data

Hello,

I’m new to select2 4.x version. I have a select2 box which can be filled through AJAX.(no issue here). The data is templated.
On the same page I also have a list of items. Clicking on one of those items should add corresponding TEMPLATED data to the select2 box. I managed doing it with an older version of select2 using the data method to add / remove items from the results list, but I can’t find any way to do it with select2 newest version.

Can someone help me please ?

Thanks,
Goralion

You should be able to use the documented method to programmatically add items to a Select2.

The <option>s you add will be displayed in the Select2’s dropdown using the templateResult template function you have designed. If you add a selected option, that option will be displayed as the selected item in the Select2 using the templateSelection template function you have defined.