Avoid automatic sort options
I try to use selectize dynamically via AJAX So I fetch the needed data and then push them to selectize. But my data have been ordered already and I don't change order. So I use next code
data # array with payload
new_opts = []
$.each data.recipients, (_, value) ->
new_opts.push({text: value[1], value: value[0]})
selectize = $('#user_ids')[0].selectize
selectize.clear()
selectize.clearOptions()
selectize.renderCache['option'] = {}
selectize.renderCache['item'] = {}
selectize.addOption(new_opts)
selectize.refreshOptions
How can I avoid sorting process inside selectize ?
Thx
There is a sortField attribute in the selectize settings object which can be removed to disable sorting of options.
As far as I understand the sorting, the sort order of each option is determined by the score() function every time the search term is changed (i.e. while typing) and mostly is a measure of how well the option matches the search term.
The only way I found to get the options sorted by a pre-existing sort field was to override the score() callback like seen in the GitHub example
https://github.com/selectize/selectize.js/blob/5b06be3d5726c89ed1dbf2ff22eb94b9f2bc60ff/examples/github.html#L129-L134 Here you see that while the result of the original score() function is being used, the resulting score relies more heavily on the "watchers" field of each option ("item" in the example).
Note that the example doesn't even use the sortField option.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days