Searching and filtering
Svelecte supports filtering available options based on what you write. This functionality is controlled by searchable property and is enabled by default and all first child properties are searchable.
Seach and filtering capabilities are provided by sifter.js internally and search settings has been extended for more granular search settings in v4.0.
🧩 Playground
Now searching in properties:
Try switching to
name. Try switching to
or search by typing | between other words. For example b c vs b | c Settings
Customizing search is possible by passing searchProps property and can have following structure. All properties are
optional and boolean values are false by default.
/**
* @typedef {object} SearchProps
* @property {string|string[]} [fields]
* @property {string|SortDef[]} [sort]
* @property {boolean} [skipSort]
* @property {'or'} [conjunction]
* @property {boolean} [keepSelectionInList]
* @property {boolean} [nesting]
* @property {boolean} [disabled]
* @property {boolean} [startOnly]
* @property {boolean} [wordsOnly]
*
*
* @typedef {object} SortDef
* @property {string} field
* @property {'asc'|'desc'} [direction]
*/ /**
* @typedef {object} SearchProps
* @property {string|string[]} [fields]
* @property {string|SortDef[]} [sort]
* @property {boolean} [skipSort]
* @property {'or'} [conjunction]
* @property {boolean} [keepSelectionInList]
* @property {boolean} [nesting]
* @property {boolean} [disabled]
* @property {boolean} [startOnly]
* @property {boolean} [wordsOnly]
*
*
* @typedef {object} SortDef
* @property {string} field
* @property {'asc'|'desc'} [direction]
*/fieldsallow you to specify which properties are used for search. In combination withnestingparameter you can specify also nested properties with dot notation likemy.nested.property.sortdefine sort properties which search result sorting is based upon.skipSortsorting can be turned off.conjuctiondefaults toand, defines how multiple words are searched.orcan be turned on directly when entering text by typing|character.keepSelectionInListallow matched selected options to stay visiblenestingallow for search in nested properties, as mentions infieldsdescriptiondisabledwhentrueno option is filtered out, just searched phrase is highlighted (which can be disabled bydisabledHighlightingproperty)startOnlysearch only from beginning of the stringwordsOnlyrespects word boundaries