I'm currently using a dropdown-menu where the user can select an application version (e.g. 1.0.4.3-0001
) to get more information on this specific version. To let the user find the correct version faster I want to sort this dropdown-menu so that the latest version is on top and the lowest version (1.0.0.0-0001
) is at the bottom. Because all versions are getting fetched from a server and new ones can appear every day, I cannot sort them by hand.
I tried various jQuery and JavaScript codes to sort it right, but none of the codes seem to work with decimals like application versions (because it thinks 1.0.2.0
is newer than 1.0.12.0
for example). Does anyone know how to work with such a specific case?
Just in case anyone wants to see the code I've tried so far (with 'version' being my dropdown):
$("#version").html($("#version option").sort(function (a, b) {
return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
}))
Many thanks in advance.