Skip to content
This repository has been archived by the owner on May 5, 2018. It is now read-only.

Select2 - How to stop automatic sorting? #406

Closed
moroshko opened this issue Feb 6, 2013 · 11 comments
Closed

Select2 - How to stop automatic sorting? #406

moroshko opened this issue Feb 6, 2013 · 11 comments
Milestone

Comments

@moroshko
Copy link

moroshko commented Feb 6, 2013

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

@abanctelchevrel
Copy link

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...

@ProLoser
Copy link
Member

ProLoser commented Feb 6, 2013

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" notifications@github.com
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//issues/406#issuecomment-13189174.

@moroshko
Copy link
Author

moroshko commented Feb 7, 2013

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

@ProLoser
Copy link
Member

ProLoser commented Feb 7, 2013

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

@joseym
Copy link
Contributor

joseym commented Feb 8, 2013

@ProLoser
Copy link
Member

ProLoser commented Feb 8, 2013

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
Copy link
Member

ProLoser commented May 3, 2013

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)?

@nateabele
Copy link

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.

@phamios
Copy link

phamios commented Sep 10, 2015

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
Copy link

phamios commented Sep 10, 2015

<script type="text/javascript"> $("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"); }); </script>

I solved this problem :)

@phamios
Copy link

phamios commented Sep 10, 2015

$("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");
});

@angular-ui angular-ui locked and limited conversation to collaborators Sep 10, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants