Classes

Class: FilterManager

63min

/ 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

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new FilterManager(initialValues?)

Manager can be initialized with existing options and sliders

Parameters

Name

Type

Description

initialValues?

Object

initialize manager with values

initialValues.filters?

Given set of filters

Defined in

Properties

filters

filters: FilterManagerFilters[] = []

Defined in

Accessors

options

get options(): KlevuFilterResultOptions[]



use filters instead. This doesn't take into account order of options and sliders

Returns

Defined in



sliders

get sliders(): KlevuFilterResultSlider[]



use filters instead. This doesn't take into account order of options and sliders

Returns

Defined in

Methods

clear

clear(): void

clear current options and sliders

Returns

void

Defined in



clearOptionSelections

clearOptionSelections(key?): void

Sets selected key of all options to false

Parameters

Name

Type

Description

key?

string

Optional key to lmit clearing to one option

Returns

void

Defined in



currentSelection

currentSelection(key): undefined | string[]

Get current selection by key

Parameters

Name

Type

key

string

Returns

undefined | string[]

Defined in



deselectOption

deselectOption(key, value): void

Deselect given option

Parameters

Name

Type

Description

key

string

key of filter to deselect

value

string

value of option to deselect

Returns

void

Defined in



getCurrentState

getCurrentState(): FilterManagerState

Gets current state of filters

Returns

FilterManagerState

current state

Defined in



getOptionByKeyCreateIfNotExists

Private getOptionByKeyCreateIfNotExists(key, value): Object

Get option by key and sub option name. If doesn't exist, create it.

Parameters

Name

Type

key

string

value

string

Returns

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

Defined in



initFromListFilters

initFromListFilters(filters): void

Parameters

Returns

void

Defined in



readFromURLParams

readFromURLParams(params): void

Set current selection of filters from a URL param string

Parameters

Name

Type

Description

params

URLSearchParams

URLSearchParams to read from

Returns

void

Defined in



selectOption

selectOption(key, value): void

Select given option

Parameters

Name

Type

Description

key

string

key of filter to select

value

string

value of option to select

Returns

void

Defined in



selectedFilters

selectedFilters(): { key: string ; label: string ; type: KlevuFilterType ; value: string }[]

Quickly get all selected options and sliders

Returns

{ key: string ; label: string ; type: KlevuFilterType ; value: string }[]

Array of selected filters, with key, label, type and value

Defined in



setState

setState(state): void

Parameters

Name

Type

state

FilterManagerState

Returns

void

Defined in



toApplyFilters

toApplyFilters(): ApplyFilter[]

Populate filter manager with filters from Klevu API

Returns

ApplyFilter[]

Defined in



toURLParams

toURLParams(): string

Changes current selection of filters to a URL param string

Returns

string

string of URL params

Defined in



toggleOption

toggleOption(key, value): void

Function to select filters in filter manager

Sends a Dom event on change

Parameters

Name

Type

Description

key

string

Key of option

value

string

value of option to toggle

Returns

void

Defined in



updateSlide

updateSlide(key, min, max): void

Function to update slide in filter manager

Sends a Dom event on change

Parameters

Name

Type

Description

key

string

Key of slide

min

number

Min value of slide

max

number

Max value of slide

Returns

void

Defined in



isKlevuFilterResultOptions

Static isKlevuFilterResultOptions(filter): filter is KlevuFilterResultOptions

Is given variable an option filter

Parameters

Returns

filter is KlevuFilterResultOptions

Defined in



isKlevuFilterResultRating

Static isKlevuFilterResultRating(filter): filter is KlevuFilterResultRating

Is given variable an rating filter

Parameters

Returns

filter is KlevuFilterResultRating

Defined in



isKlevuFilterResultSlider

Static isKlevuFilterResultSlider(filter): filter is KlevuFilterResultSlider

Is given variable a slider filter

Parameters

Returns

filter is KlevuFilterResultSlider

Defined in

Updated 25 Mar 2024
Did this page help you?