Is it possible to change the order in the dropdown to replace an item?
I need to change it to alphabetic order. Any idea?
Thanks in advance!
Is it possible to change the order in the dropdown to replace an item?
I need to change it to alphabetic order. Any idea?
Thanks in advance!
Please find below snippet to sort selectlist
$("#mSelect").append($("#mSelect option").remove().sort(function(a, b) {
var at = $(a).text(), bt = $(b).text();
return (at > bt)?1:((at < bt)?-1:0);
}));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="mSelect" >
<option value="val1" > DEF </option>
<option value="val4" > GRT </option>
<option value="val2" > ABC </option>
<option value="val3" > OPL </option>
<option value="val5" > AWS </option>
<option value="val9" > BTY </option>
</select>
Small Correction: Added last line for clearing default option selection
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="mSelect" >
<option value="val1" > DEF </option>
<option value="val4" > GRT </option>
<option value="val2" > ABC </option>
<option value="val3" > OPL </option>
<option value="val5" > AWS </option>
<option value="val9" > BTY </option>
</select>
$("#mSelect").append($("#mSelect option").remove().sort(function(a, b) {
var at = $(a).text(), bt = $(b).text();
return (at > bt)?1:((at < bt)?-1:0);
}));
$("#mSelect").val("");
At the moment there is no such option. A jQuery-Hacky method may be possible, but I wouldn't try it. Basically if you want this, you should create an issue on github, but you'll probably have to contribute the code :)