Is there any Way i can remove an item from selectize
- AMNT
- QTY
- NA
when i pass NA it should remove particular item
$.fn.removeSelectorValue = function (value) {
var selectize = this[0].selectize;
selectize.removeItem(value)
return this;
};
this is not working.. Can anyone help me out from this???
removeItem
removes selected item identified by given value. To remove option from the list you should use removeOption
Example - open http://brianreavis.github.io/selectize.js/, open console and enter:
$('#select-beast')[0].selectize.removeOption(1)
to remove Chuck Tesla from available options
I'm late to the party but the other methods didn't work for me, I don't know if its because I was pulling in a list from a remote source?
In short there are 2 steps:
- Get the value of the selected item
- Remove that item
You can obviously make this code smaller but i've left it verbose for readability
var $select = $('#users').selectize();
var selectSizeControl = $select[0].selectize;
// 1. Get the value
var selectedValue = selectSizeControl.getValue()
// 2. Remove the option
selectSizeControl.removeOption( selectedValue )
$(document).on('click', 'div.selectize-input div.item', function(e) {
var select = $('#services').selectize();
var selectSizeControl = select[0].selectize;
// 1. Get the value
var selectedValue = $(this).attr("data-value");
// 2. Remove the option
select[0].selectize.removeItem(selectedValue);
select[0].selectize.refreshItems();
select[0].selectize.refreshOptions();
});
This code do not remove the item from the select, just remove it from the selected options.
Was recently implementing this, and if you remove the last item, the input looks buggy (as mentioned above). A workaround (kind of hackish) is in the onItemRemove
function, find the length of saved items, and if length == 0
, use jQuery to fix the input - $('.selectize-input').css({'height':'35px'});
来源:https://stackoverflow.com/questions/26873595/how-to-remove-an-item-from-selectize