On Jan 18, 3:52 am, NMarcu <marcu.nico...@gmail.com> wrote: > What's the best way to sort options in select. I found a jquery > plugin sortOptions(), but if I have options: > Address 1, Address 2, Address 3, Address 100, Address 200 > , will be sort like this: > Address 1, Address 100, Address 2, Address 200, Address 3 > ...and is not good. Do you have another solution, or how can I adapt > this one to do a good sorting.
If this is the sortOptions from http://www.texotela.co.uk/code/jquery/select/ you should be able to modify this yourself, and perhaps submit a patch back to the creator. Ideally, it would follow this pattern: $.fn.sortOptions = function(ascending, params) { var parameters = $.extend( {}, $.fn.sortOptions .defaults, params || {}); // [ ... ] // sort items in array sA.sort(parameters.sortFn); // [ ... ] }; $.fn.sortOptions.defaults = { sortFn: function(01, 02) { // original sort algorithm here } } That would be the only changes needed to the original plug-in. Then you could use it by either overriding jQuery.sortOptions.defaults.sortFn or by passing in your function to the call like this: $("selector").sortOptions(true, {sortFn: mySortFn}); You might want to do some additional work to allow the first parameter to sortOptions to remain optional. As to actually implementing your sort, I leave that to you.... Good luck, -- Scott