Here is a jsFiddle demonstrating the issue. Look at when it's reordered. The main select="selected" is not selected. http://jsfiddle.net/zuuyj/
I have a select box, that im sorting using this script
$(document).ready(function () {
var options = $('select.pca31 option');
var arr = options.map(function(_, o) {
return {
t: $(o).text(),
v: o.value
};
}).get();
arr.sort(function(o1, o2) {
return o1.t > o2.t ? 1 : o1.t < o2.t ? -1 : 0;
});
options.each(function(i, o) {
console.log(i);
o.value = arr[i].v;
$(o).text(arr[i].t);
});
This works fine until you have a selected option (Editing item) the selected option is not displayed as selected, because it reorders the list.
I tried this
$("select.pca31 option").empty().append( options );
Based on this
But I just get an infinite loop. I can see why, but I can't see how to fix it.