tom-select

How to add item at top/first?


I tried

select.tomselect.addOption({value: '-1', text: 'All', '$score': 99999 })

but that does not work. Is there any other way to do this?


Solution

  • You need tell Tom Select how to sort: https://tom-select.js.org/docs/#sortfield

    Also, I don't think supplying a $score field will work since it's already being used and will likely be overwritten by Tom Select. You could supply something else though, say $custom_sort and define your sortField parameter to sortField:[{field:'$custom_sort'},{field:'$score'}]