Disable automatic sort
Hi, I'm receiving a pre-ordered list (JSON) but when I loaded into the selectize control, it re-orders the list by the Id and I don't want this. How I can let selectize use the order of my JSON?
This is the JSFiddle example: http://jsfiddle.net/LYYab/
Thanks.
I would also like to be able to disable automatic sorting. It's really, really frustrating that Selectize automatically messes with the order of options that are added to it.
Is there no way to disable autosort?
@eliashdez @erlingur Remove sortField: "text" from the selectize options to disable the auto sorting.
@antsa I don't have that. I use the default configuration of $("#element").selectize() and it still does the auto sorting.
And you are using 0.8.5? Without the sortField option it works as expected for me with just a selectelement with options inside of it.
The example of @eliashdez seemed to work differently with loading the data from JSON, where sorting happened. Here the trick seemed to be to set the sortField: "Id"
@antsa Yes. Here is a jsfiddle demonstrating the problem: http://jsfiddle.net/8H62B/6/
When you first load the page with
On that jsfiddle, if you begin by looking at the options, then click the button and look at the options again you will see what I mean.
@erlingur Apparently when adding options it does sorting and doesn't use the original order of the data—would it work for you to set the order with e.g. sortField: "text" in that case?
When calling selectize on a existing select with options leaving that option out will keep the original order of the option elements.
@antsa sortField: 'text' will sort the options based on their text right? That wouldn't work for me since I have presorted options that are not really based on either the value or the name. I would ideally need addOptions() to respect the insert order. I'm looking at it now, trying to make it do that.
So I created a pull request with a proposed fix. What do you think @antsa?
I need it too
Hey @ai, I created a pull request for this here: https://github.com/brianreavis/selectize.js/pull/295
You can use this branch if you want this functionality now: https://github.com/Reiknistofa/selectize.js/tree/respect_insert_order_in_addoption
:+1:
+1
+1
+1
:+1: will this be merged?
+1
With the current most common model with API's serving multiple front ends, it's rather common to have dynamic elements. It's also common that the API will provide these elements in the correct sorting, making the current automatic sorting not just a deprecated feature, but seen as a bug for most of the users.
Thanks for fixing it.
@xjunior No problem! Yeah, seems like something a lot of people would like.
This should still merge cleanly with the latest version. Hopefully @brianreavis will chime in here with his thoughts.
I solved this problem by setting the following option when initializing the selectize object... Works with my pre-ordered JSON data!
score: function() { return function() { return 1 }; }
@freefallfred Like this? http://jsfiddle.net/a9ttjt7v/ Doesn't fix it for me.