Disable automatic sort #1706
-
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: Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 43 comments
-
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? |
Beta Was this translation helpful? Give feedback.
-
@eliashdez @erlingur Remove |
Beta Was this translation helpful? Give feedback.
-
@antsa I don't have that. I use the default configuration of |
Beta Was this translation helpful? Give feedback.
-
And you are using 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 |
Beta Was this translation helpful? Give feedback.
-
@antsa Yes. Here is a jsfiddle demonstrating the problem: http://jsfiddle.net/8H62B/6/ When you first load the page with it works fine but when I attempt to update the select with new options it will auto sort them. 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. |
Beta Was this translation helpful? Give feedback.
-
@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. When calling selectize on a existing select with options leaving that option out will keep the original order of the option elements. |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
So I created a pull request with a proposed fix. What do you think @antsa? |
Beta Was this translation helpful? Give feedback.
-
I need it too |
Beta Was this translation helpful? Give feedback.
-
Hey @ai, I created a pull request for this here: #295 You can use this branch if you want this functionality now: https://github.com/Reiknistofa/selectize.js/tree/respect_insert_order_in_addoption |
Beta Was this translation helpful? Give feedback.
-
👍 will this be merged? |
Beta Was this translation helpful? Give feedback.
-
Still nothing here? Im facing the same problem. |
Beta Was this translation helpful? Give feedback.
-
When exporting from database, make a column with a count and use that? |
Beta Was this translation helpful? Give feedback.
-
Same here. |
Beta Was this translation helpful? Give feedback.
-
+1 |
Beta Was this translation helpful? Give feedback.
-
Still have this bug! Help! |
Beta Was this translation helpful? Give feedback.
-
Despite this issue being closed, I'm still having it 5 years after it was opened, as are others it seems. (with version 0.12.4). I'm about to ditch selectize altogether because of this. The |
Beta Was this translation helpful? Give feedback.
-
This works for me:
It disables the default sorting and the search function keeps working as expected |
Beta Was this translation helpful? Give feedback.
-
Still have this bug |
Beta Was this translation helpful? Give feedback.
-
score: function () {
return function () {
return 1
}
}, Seems to be a working hack. @brianreavis posted here and mentioned #640 (comment) where he said:
|
Beta Was this translation helpful? Give feedback.
-
Use
|
Beta Was this translation helpful? Give feedback.
-
@urmamb that's true for maybe most of the cases, but there are others where the server wants to prioritise some results over others (new movies, important people) and wants to show them first. This doesn't mean that after the first results, if you continue typing, selectize could search and sort it out, but the first results should (with at least a flag/option) be unsorted. |
Beta Was this translation helpful? Give feedback.
-
This works for me for
When typing to search, it respects the original order of options. |
Beta Was this translation helpful? Give feedback.
-
@xhafan This works for me as well, excellent workaround. |
Beta Was this translation helpful? Give feedback.
This works for me for
select
tag with options:When typing to search, it respects the original order of options.
Taken from #196 (comment) and simplified for my case.