angular-ui-OLDREPO icon indicating copy to clipboard operation
angular-ui-OLDREPO copied to clipboard

Select2 - How to stop automatic sorting?

Open moroshko opened this issue 13 years ago • 11 comments

Looks like when using multiple, the items are sorted automatically. Is there a way to stop this?

Live example here: http://plnkr.co/edit/5X7s8WZPVw7Z9gVWDjK3?p=preview

See also: http://stackoverflow.com/questions/14727502/angular-ui-select2-how-to-stop-automatic-sorting

moroshko avatar Feb 06 '13 11:02 moroshko

I stumble upon the same issue, and after some test I'm thinking it's actually an issue in select2, and not in angular-ui.

When programmatically setting the select2 widget you can use select2.('val') or select2.('data'). As you can see here (http://jsfiddle.net/u7pYa/3/), select2.('val') does not preserve entry order, whereas select2.('data') does.

The select2 directive seems to use select2.('val') for multiple select. A fix could be to change that to select2.('data'), but I had no success with it so far...

abanctelchevrel avatar Feb 06 '13 16:02 abanctelchevrel

It uses data if you pass an object instead of an idea. V0.4.0 may have some fixes. On Feb 6, 2013 8:06 AM, "Antoine BANCTEL-CHEVREL" [email protected] wrote:

I stumble upon the same issue, and after some test I'm thinking it's actually an issue in select2, and not in angular-ui.

When programmatically setting the select2 widget you can use select2.('val') or select2.('data'). As you can see here (http://jsfiddle.net/u7pYa/3/), select2.('val') does not preserve entry order, whereas select2.('data') does.

The select2 directive seems to use select2.('val') for multiple select. A fix could be to change that to select2.('data'), but I had no success with it so far...

— Reply to this email directly or view it on GitHubhttps://github.com/angular-ui/angular-ui/issues/406#issuecomment-13189174.

ProLoser avatar Feb 06 '13 17:02 ProLoser

Where could I find the most updated code for 0.4.0? I can't see any branch or tag with 0.4.0.

moroshko avatar Feb 07 '13 11:02 moroshko

I should probably start developing into a dedicated branch... Right now all v0.4.0 changes are in master.

ProLoser avatar Feb 07 '13 20:02 ProLoser

@moroshko - https://github.com/angular-ui/angular-ui/blob/master/modules/directives/select2/select2.js

joseym avatar Feb 08 '13 15:02 joseym

I have been poking around with this and it makes 0 sense why this should be occurring as angular and angularUI is not actually doing anything specifically to deal with data order. I will slate this fix for v0.4.1

ProLoser avatar Feb 08 '13 22:02 ProLoser

AngularUI is currently undergoing a restructure. This project will no longer hold the codebase, can you please relocate this to https://github.com/angular-ui/ui-select2 (after confirming it's still necessary with the latest code)?

ProLoser avatar May 03 '13 09:05 ProLoser

This repo is discontinued. The project has been relocated here: https://github.com/angular-ui/ui-select2

Please reopen this issue there if it is still relevant.

nateabele avatar Sep 09 '13 00:09 nateabele

I have the same problem of Select2 4.0.0 I dont know how to disable sort when I select the items. anyone have any ideas ?

phamios avatar Sep 10 '15 04:09 phamios

I solved this problem :)

phamios avatar Sep 10 '15 04:09 phamios

$("select").select2({

tags: true });

$("select").on("select2:select", function (evt) { var element = evt.params.data.element; var $element = $(element);

$element.detach(); $(this).append($element); $(this).trigger("change"); });

phamios avatar Sep 10 '15 04:09 phamios