Skip to content

If array is passed into addOption then respect the insert order #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

erlingur
Copy link

Here is a jsFiddle demonstrating the problem: http://jsfiddle.net/8H62B/6/

I'm not a great Javascript programmer so if I did something wrong please feel free to point it out.

When addOption is given an array I would like it if it would respect the order of the array. We already have an $order property on the option so I just fill that in with the appropriate value.

I wasn't sure what files I should change so I just changed everything except the minimized versions. This should hopefully fix #218. Any thoughts?

@antsa
Copy link

antsa commented Feb 19, 2014

I think it looks good. Of course addOption can also be used to add to a existing collection, I guess that is why the order of the inserted data is not respected and sorting is done separately.

I think it would be nice that the order is respected the same way as in when using ready markup as a data source.

So definitely +1 for this:)

@erlingur
Copy link
Author

Ok, thanks. Yeah, that got me thinking, this does make a difference when adding options to the existing collection.

Here is a JSFiddle with the proposed changes and how it handles adding to an existing collection: http://jsfiddle.net/XLLyw/2/

And here is a JSFiddle with the current implementation: http://jsfiddle.net/XLLyw/3/

I might have to fix this. It will intersperse the new options with the old ones which is not as nice as the current implementation which will put the new options at the top. Taking a look at this now.

@erlingur
Copy link
Author

Alright, I've added a start_order variable that counts the number of existing options and sets that as the starting point for $order. That should hopefully ensure that every new item is inserted at the end of the list instead of mixing in.

JSFiddle with the new code: http://jsfiddle.net/XLLyw/4/

Again, I'm not a strong JS coder so if someone can improve the code feel free to do so! :)

@erlingur erlingur mentioned this pull request Apr 17, 2014
@brianreavis
Copy link
Member

Thanks for the pull request! I'm going to take a different approach, but agree with you – this is something that needs solved. See #640 (comment)

@erlingur
Copy link
Author

Hey @brianreavis, awesome, thanks! Good to hear :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable automatic sort
3 participants