I want to sort the select2 options in alphabetical order. I have the following code and would like to know, how can this be achieved:
<select name="list" id="mylist" style="width:140px;">
<option>United States</option>
<option>Austria</option>
<option>Alabama</option>
<option>Jamaica</option>
<option>Taiwan</option>
<option>canada</option>
<option>palau</option>
<option>Wyoming</option>
</select>
$('#mylist').select2({
sortResults: function(results) { return results.sort(); }
});
I want to sort the data via 'text'.