# Coveo SimpleFilter Component (CoveoSimpleFilter)

The `SimpleFilter` component displays a dropdown menu containing field values which the end user can select to filter the query results.

The list of available field values in the dropdown menu can either be static (defined through the `values` option), or dynamic (automatically obtained through a `GroupByRequest` operation performed at the same time as the main query).

Available since

  November 2017 Release (v2.3477.9)

## Index

### Methods

- closeContainer
- debugInfo
- deselectValue
- disable
- enable
- getBindings
- getSelectedCaptions
- getValueCaption
- getValueContainer
- openContainer
- resetSimpleFilter
- selectValue
- toggleContainer
- toggleValue
- get

### Properties

- bind
- componentOptionsModel
- componentStateModel
- disabled
- logger
- queryController
- queryStateModel
- root
- searchInterface
- ID

### Accessors

- usageAnalytics

### Component Options

- enableClearButton
- field
- maximumNumberOfValues
- sortCriteria
- title
- valueCaption
- values

### Constructors

- constructor

## Methods

### closeContainer

- closeContainer(): void

- - Defined in ui/SimpleFilter/SimpleFilter.ts :324

  Closes the `SimpleFilter` `valueContainer`.

  #### Returns void

### debugInfo

- debugInfo(): any

- Inherited from BaseComponent.debugInfo

  - Defined in ui/Base/BaseComponent.ts :41

  Return the debug info about this component.

  #### Returns any

### deselectValue

- deselectValue(value: string): void

- - Defined in ui/SimpleFilter/SimpleFilter.ts :275

  Un-selects the specified value.

  #### Parameters

  - ##### value: string

    The value whose state the method should reset.

  #### Returns void

### disable

- disable(): void

- Inherited from BaseComponent.disable

  - Defined in ui/Base/BaseComponent.ts :52

  Disable the component. Normally this means that the component will not execute handlers for the framework events (query events, for example). Components are enabled by default on creation.

  #### Returns void

### enable

- enable(): void

- Inherited from BaseComponent.enable

  - Defined in ui/Base/BaseComponent.ts :61

  Enable the component. Normally this means that the component will execute handlers for the framework events (query events, for example). Components are enabled by default on creation.

  #### Returns void

### getBindings

- getBindings(): IComponentBindings

- Inherited from Component.getBindings

  - Defined in ui/Base/Component.ts :328

  Return the bindings, or environment, for the current component.

  #### Returns IComponentBindings

### getSelectedCaptions

- getSelectedCaptions(): string[]

- - Defined in ui/SimpleFilter/SimpleFilter.ts :246

  Gets the captions of the currently selected field values in the `SimpleFilter`.

  #### Returns string[]

  An array containing the selected captions.

### getValueCaption

- getValueCaption(value: string): string

- - Defined in ui/SimpleFilter/SimpleFilter.ts :231

  Gets the caption of a specific field value.

  #### Parameters

  - ##### value: string

    The field value whose caption the method should attempt to get.

  #### Returns string

  The value caption, if available; the original value otherwise.

### getValueContainer

- getValueContainer(): Dom

- - Defined in ui/SimpleFilter/SimpleFilter.ts :222

  Gets the `SimpleFilter` `valueContainer`.

  #### Returns Dom

  The `SimpleFilter` valueContainer.

### openContainer

- openContainer(): void

- - Defined in ui/SimpleFilter/SimpleFilter.ts :311

  Opens the `SimpleFilter` `valueContainer`.

  #### Returns void

### resetSimpleFilter

- resetSimpleFilter(): void

- - Defined in ui/SimpleFilter/SimpleFilter.ts :300

  Resets the component to its original state.

  #### Returns void

### selectValue

- selectValue(value: string, triggerQuery?: boolean): void

- - Defined in ui/SimpleFilter/SimpleFilter.ts :262

  Selects the specified value. Also triggers a query, by default.

  #### Parameters

  - ##### value: string

    The value to select.

  - ##### Default value triggerQuery: boolean = true

    `true` by default. If set to `false`, the method triggers no query.

  #### Returns void

### toggleContainer

- toggleContainer(): void

- - Defined in ui/SimpleFilter/SimpleFilter.ts :253

  Opens or closes the `SimpleFilter` `valueContainer`, depending on its current state.

  #### Returns void

### toggleValue

- toggleValue(value: string): void

- - Defined in ui/SimpleFilter/SimpleFilter.ts :288

  Selects or un-selects the specified value, depending on its current state.

  #### Parameters

  - ##### value: string

    The value whose state the method should toggle.

  #### Returns void

### Static get

- get(element: HTMLElement, componentClass?: any, noThrow?: boolean): BaseComponent

- Inherited from Component.get

  - Defined in ui/Base/Component.ts :410

  Get the bound component to the given HTMLElement. Throws an assert if the HTMLElement has no component bound, unless using the noThrow argument.
  If there is multiple component bound to the current HTMLElement, you must specify the component class.

  #### Parameters

  - ##### element: HTMLElement

    HTMLElement for which to get the bound component.

  - ##### Optional componentClass: any

    Optional component class. If the HTMLElement has multiple components bound, you must specify which one you are targeting.

  - ##### Optional noThrow: boolean

    Boolean option to tell the method to not throw on error.

  #### Returns BaseComponent

## Properties

### bind

bind: ComponentEvents

Inherited from Component.bind

- Defined in ui/Base/Component.ts :270

Allows the component to bind events and execute them only when it is enabled.

type

  {Coveo.ComponentEvents}

### componentOptionsModel

componentOptionsModel: ComponentOptionsModel

Inherited from Component.componentOptionsModel

- Defined in ui/Base/Component.ts :294

Contains the state of options for different components. Mainly used by ResultLink.

### componentStateModel

componentStateModel: ComponentStateModel

Inherited from Component.componentStateModel

- Defined in ui/Base/Component.ts :282

Contains the state of different components (enabled vs disabled). Allows to get/set values. Triggers component state event when modified. Each component can listen to those events.

### disabled

disabled: boolean

Inherited from BaseComponent.disabled

- Defined in ui/Base/BaseComponent.ts :23

A disabled component will not participate in the query, or listen to ComponentEvents.

type

  {boolean}

### logger

logger: Logger

Inherited from BaseComponent.logger

- Defined in ui/Base/BaseComponent.ts :18

Allows component to log in the dev console.

### queryController

queryController: QueryController

Inherited from Component.queryController

- Defined in ui/Base/Component.ts :286

Contains the singleton that allows to trigger queries.

### queryStateModel

queryStateModel: QueryStateModel

Inherited from Component.queryStateModel

- Defined in ui/Base/Component.ts :278

Contains the state of the query. Allows to get/set values. Trigger query state event when modified. Each component can listen to those events.

### root

root: HTMLElement

Inherited from Component.root

- Defined in ui/Base/Component.ts :274

A reference to the root HTMLElement (the SearchInterface).

### searchInterface

searchInterface: SearchInterface

Inherited from Component.searchInterface

- Defined in ui/Base/Component.ts :290

A reference to the root of every component, the SearchInterface.

### Static ID

ID: string

Inherited from BaseComponent.ID

- Defined in ui/Base/BaseComponent.ts :28

The static ID that each component needs in order to be identified.
For example, SearchButton -> static ID: SearchButton -> className: CoveoSearchButton

## Accessors

### usageAnalytics

- get (): IAnalyticsClient

- Inherited from Component.usageAnalytics

  - Defined in ui/Base/Component.ts :343

  A reference to the Analytics.client.

  #### Returns IAnalyticsClient

## Component Options

### enableClearButton

enableClearButton: boolean

- Defined in ui/SimpleFilter/SimpleFilter.ts :174

Whether to show a button to clear all selected values.

Default

  `false`

Available since

  March 2020 Release (v2.8521)

Markup configuration example(s) :

    data-enable-clear-button='true'
    data-enable-clear-button='false'

### field

field: IFieldOption

- Defined in ui/SimpleFilter/SimpleFilter.ts :86

Specifies the field whose values the `SimpleFilter` should output result filters from.

Specifying a value for this option is required for the `SimpleFilter` component to work.

Required

  Specifying a value for this option is required for the component to work

Markup configuration example(s) :

    data-field='@foo'

### maximumNumberOfValues

maximumNumberOfValues: number

- Defined in ui/SimpleFilter/SimpleFilter.ts :71

Specifies the maximum number of field values to display in the `SimpleFilter` dropdown menu.

Default value is `5`. Minimum value is `0`.

Minimum

  `0`

Default

  `5`

Markup configuration example(s) :

    data-maximum-number-of-values='10'

### sortCriteria

sortCriteria: "occurrences" | "score" | "alphaascending" | "alphadescending" | "computedfieldascending" | "computedfielddescending" | "chisquare" | "nosort"

- Defined in ui/SimpleFilter/SimpleFilter.ts :155

string? The sort criteria to use.

Default: `score`

Allowed values:

`score`: sort using the score value which is computed from the number of occurrences of a field value, as well as from the position where query result items having this field value appear in the ranked query result set. When using this sort criterion, a field value with 100 occurrences might appear after one with only 10 occurrences, if the occurrences of the latter field value tend to appear higher in the ranked query result set.

`occurrences`: sort by number of occurrences, with field values having the highest number of occurrences appearing first.

`alphaascending/alphadescending`: sort alphabetically on the field values.

`chisquare`: sort based on the relative frequency of field values in the query result set compared to their frequency in the entire index. This means that a field value that does not appear often in the index, but does appear often in the query result set will tend to appear higher.

Available since

  July 2019 Release (v2.6459)

### title

title: string

- Defined in ui/SimpleFilter/SimpleFilter.ts :93

Specifies the title to display for the `SimpleFilter`.

Default value is the localized string for `NoTitle`.

Markup configuration example(s) :

    data-title='foo'

### valueCaption

valueCaption: any

- Defined in ui/SimpleFilter/SimpleFilter.ts :130

Specifies a JSON object describing a mapping of `SimpleFilter` values to their desired captions.

Examples:

- You can set the option in the 'init' call: ```javascript var myValueCaptions = { "txt" : "Text files", "html" : "Web page", [ ... ] };

Coveo.init(document.querySelector("#search"), { SimpleFilter : { valueCaption : myValueCaptions } });

    * Or before the `init` call, using the <a href="simplefilter.html#options">'options'</a> top-level function:
    ```javascript
    Coveo.options(document.querySelector("#search"), {
      SimpleFilter : {
        valueCaption : myValueCaptions
      }
    });

- Or directly in the markup:

      <!-- Ensure that the double quotes are properly handled in `data-value-caption`. -->
      <div class='CoveoSimpleFilter' data-field='@myotherfield' data-value-caption='{"txt":"Text files","html":"Web page"}'></div>

### values

values: string[]

- Defined in ui/SimpleFilter/SimpleFilter.ts :79

Specifies a static list of field values to display in the `SimpleFilter` dropdown menu.

This option is undefined by default, which means that the component generates a dynamic list of field values by performing a `GroupByRequest` operation at the same time as the main query.

## Constructors

### constructor

- new SimpleFilter(element: HTMLElement, options: ISimpleFilterOptions, bindings?: IComponentBindings): SimpleFilter

- Overwrites Component.constructor

  - Defined in ui/SimpleFilter/SimpleFilter.ts :187

  Creates a new `SimpleFilter` component. Binds multiple query events as well.

  #### Parameters

  - ##### element: HTMLElement

    the HTMLElement on which to instantiate the component.

  - ##### options: ISimpleFilterOptions

    The options for the `SimpleFilter` component.

  - ##### Optional bindings: IComponentBindings

    The bindings that the component requires to function normally.

  #### Returns SimpleFilter