How to prevent automatic sorting with multiselect?

5,423 views
Skip to first unread message

ovar...@googlemail.com

unread,
Mar 9, 2015, 9:50:48 AM3/9/15
to sel...@googlegroups.com
When you select multiple items, they are sorted alphabetically. We would like to preset the select order without sorting. That means, if I select "B" and then "A", the multi select should display "B", "A" and not "A", "B". How to achieve that? Thanks.

Barry Hunter

unread,
Mar 9, 2015, 10:00:07 AM3/9/15
to sel...@googlegroups.com
I've never observed automatic 'sorting' as such. But in common with a native mult-select, the items will be presented to the server in the order they are in the original list, rather than the order they selected by the user. 

You could try using the 'tags' mode, that works slightly different, and will present the items in the order selected. But you may need to use it with a hidden input field - rather than a genuine <select> underneath, even in tags mode, select2 still just in effects manipulates the real select. 


On 9 March 2015 at 13:50, <ovar...@googlemail.com> wrote:
When you select multiple items, they are sorted alphabetically. We would like to preset the select order without sorting. That means, if I select "B" and then "A", the multi select should display "B", "A" and not "A", "B". How to achieve that? Thanks.

--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at http://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.

Oleg Varaksin

unread,
Mar 9, 2015, 12:19:15 PM3/9/15
to sel...@googlegroups.com
I use Select2 4.x. There are no hidden input there.

The selected items neither sorted as in the original list nor in the selected order. They are sorted really alphabetically. The "tags" mode is not an option for me too.

I have found the same question on the stackoverflow, but no answer. It seems to be not possible to turn off this behavior. Does Select2 3.x behave different? (never used 3.x).

Cheers. Oleg.


--
You received this message because you are subscribed to a topic in the Google Groups "select2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/select2/oPZMI6lbSzM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to select2+u...@googlegroups.com.

Barry Hunter

unread,
Mar 9, 2015, 12:44:07 PM3/9/15
to sel...@googlegroups.com
Ah right, yes I've only dealt with this in 3.5.   Hadn't noticed the lack of hidden input support in 4 - not actully used 'tags' mode in the new version. In 3.5 you can get the right order of selection directly - using input. 

Although select2 does manuipulate the select, add the new created items are added to the end (so will be themselfes in the right order) the sorting of the originals seem to be unchanged. 

So sorry, I really can't help you any more for v4 :( - except maybe suggest watching for select/unselect events and maintaining an external list of the selection - which then inject into a hidden field :)


Kevin Brown

unread,
Mar 11, 2015, 5:45:39 PM3/11/15
to sel...@googlegroups.com
Hi,

Select2 orders the selections based on the order of the `<options>` behind the scenes. This means that the order will typically match the order of the options as they appear in the results. This is done so the order that they appear matches the order that they are sent to the server.

This is currently being discussed on GitHub at the following ticket: https://github.com/select2/select2/issues/3106

Kevin Brown

On Mon, Mar 9, 2015 at 9:50 AM, <ovar...@googlemail.com> wrote:
When you select multiple items, they are sorted alphabetically. We would like to preset the select order without sorting. That means, if I select "B" and then "A", the multi select should display "B", "A" and not "A", "B". How to achieve that? Thanks.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages