Skip to content

Instantly share code, notes, and snippets.

@mdamien
Created April 9, 2016 13:41
Show Gist options
  • Select an option

  • Save mdamien/ea542e253c6b295c6062fa09f6b28f6d to your computer and use it in GitHub Desktop.

Select an option

Save mdamien/ea542e253c6b295c6062fa09f6b28f6d to your computer and use it in GitHub Desktop.
Selectize.define('filter', function(options) {
var self = this;
options.filter = options.filter || function(results) {
return results;
};
this.search = (function() {
var original = self.search;
return function(query) {
var results = original.bind(self)(query);
results.items = options.filter.bind(self)(results.items);
results.total = results.items.length;
return results;
};
})();
});
$('#the-select').selectize({
plugins: {
filter: function(items) {
var ponies_only = $('#checkbox').is(':checked');
return items.filter(function(item) {
return !ponies_only || item.data.indefOf('pony') !== -1;
});
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment