Class: FilterManager
/ Exports / FilterManager
Filter manager is used to store and handle filters (facets) in the results easily. It can be easily used with applyFilterWithFilterManager() and listFilters() modifiers
• new FilterManager(initialValues?)
Manager can be initialized with existing options and sliders
Name | Type | Description |
---|---|---|
initialValues? | Object | initialize manager with values |
initialValues.filters? | Given set of filters |
• filters: FilterManagerFilters[] = []
• get options(): KlevuFilterResultOptions[]
use filters instead. This doesn't take into account order of options and sliders
• get sliders(): KlevuFilterResultSlider[]
use filters instead. This doesn't take into account order of options and sliders
▸ clear(): void
clear current options and sliders
void
▸ clearOptionSelections(key?): void
Sets selected key of all options to false
Name | Type | Description |
---|---|---|
key? | string | Optional key to lmit clearing to one option |
void
▸ currentSelection(key): undefined | string[]
Get current selection by key
Name | Type |
---|---|
key | string |
undefined | string[]
▸ deselectOption(key, value): void
Deselect given option
Name | Type | Description |
---|---|---|
key | string | key of filter to deselect |
value | string | value of option to deselect |
void
▸ getCurrentState(): FilterManagerState
Gets current state of filters
FilterManagerState
current state
▸ Private getOptionByKeyCreateIfNotExists(key, value): Object
Get option by key and sub option name. If doesn't exist, create it.
Name | Type |
---|---|
key | string |
value | string |
Object
Name | Type | Description |
---|---|---|
count | number | |
name | string | Name / label of filter |
selected | boolean | Was this filter selected on the query |
value | string | Value of filter. That will be sent to backend |
▸ initFromListFilters(filters): void
Name | Type |
---|---|
filters |
void
▸ readFromURLParams(params): void
Set current selection of filters from a URL param string
Name | Type | Description |
---|---|---|
params | URLSearchParams | URLSearchParams to read from |
void
▸ selectOption(key, value): void
Select given option
Name | Type | Description |
---|---|---|
key | string | key of filter to select |
value | string | value of option to select |
void
▸ selectedFilters(): { key: string ; label: string ; type: KlevuFilterType ; value: string }[]
Quickly get all selected options and sliders
{ key: string ; label: string ; type: KlevuFilterType ; value: string }[]
Array of selected filters, with key, label, type and value
▸ setState(state): void
Name | Type |
---|---|
state | FilterManagerState |
void
▸ toApplyFilters(): ApplyFilter[]
Populate filter manager with filters from Klevu API
ApplyFilter[]
▸ toURLParams(): string
Changes current selection of filters to a URL param string
string
string of URL params
▸ toggleOption(key, value): void
Function to select filters in filter manager
Sends a Dom event on change
Name | Type | Description |
---|---|---|
key | string | Key of option |
value | string | value of option to toggle |
void
▸ updateSlide(key, min, max): void
Function to update slide in filter manager
Sends a Dom event on change
Name | Type | Description |
---|---|---|
key | string | Key of slide |
min | number | Min value of slide |
max | number | Max value of slide |
void
▸ Static isKlevuFilterResultOptions(filter): filter is KlevuFilterResultOptions
Is given variable an option filter
Name | Type |
---|---|
filter |
filter is KlevuFilterResultOptions
▸ Static isKlevuFilterResultRating(filter): filter is KlevuFilterResultRating
Is given variable an rating filter
Name | Type |
---|---|
filter |
filter is KlevuFilterResultRating
▸ Static isKlevuFilterResultSlider(filter): filter is KlevuFilterResultSlider
Is given variable a slider filter
Name | Type |
---|---|
filter |
filter is KlevuFilterResultSlider