I need to sort select
alphabetically.
I tried to use this function that I found on the internet
function ordenarSelect(){
f$(".slc_Reuniao").html($("option", $(".slc_Reuniao")).sort(function(a,b){
return a.text == b.text ? 0 : a.text < b.text ? -1 : 1;
}));
};
My initial select is:
<select class="slc_Reuniao">
<option value="SO" selected>--</option>
</select>
After a function that dynamically adds with append
the names returned from query
. I need to sort them out.
But it is not working, on the contrary it is generating new options
, I am using IndexedDB
as a database it is also based on javascript, I tried to look for something that at the moment I am searching the data in the database, but I do not find anything about it.
How do I do this?
On the same page I have 3 select whose content is equal.
TheformofimplementationiswhenIclickonamenulocatedinasidemenu,triggersaneventthatIdescribebelow.
$(document).on("click", "#cadReu", function(evt)
{
var w_codigo_turma = sessionStorage.getItem('codigo');
carregaSelectAluno(w_codigo_turma);
ordenarSelect();
activate_page("#cadastro_REUNIAO");
});
$( ".slc_Reuniao" ).each(function() {
$(this).append(HTMLNovo);
});
After this I call the function sql
which is where I am putting the functions indicated by the answers of my question. Both tips are giving same problem. It's not organizing and it's working. One problem I identified is that when I come back it adds the names again.