RangeFilterBuilder
The RangeFilterBuilder
class is used to construct range filters for use with the relevant SearchProvider
. They can later be referenced by the useFilter
hook or Filter
component.
Usage
Constructor
The constructor accepts a single object with the following properties:
Name | Type | Default | Description |
---|---|---|---|
name | string | The name of the filter. This should be unique. | |
group | string | A group name, for grouping multiple filters together using ARRAY_MATCH . | |
field | string | A field in schema. | |
initial | [number, number] | null | An intially selected range. |
min | number | 0 | The min value of the filter. |
max | number | aggregate ? 0 : 100 | The max value of the filter. |
step | number | 1 | A number that specifies the granularity that the values must adhere to. |
aggregate | boolean | true | If true, set value for min and max from the backend response. |
formatter | (value: [number, number]) => [number, number] | The function to format the range. By default, this will round to the nearest step for the value. For example if step is 1 , the formatter will format [0.1, 5.5] to [0, 6] . |
Properties
For more advanced implementations, you may want to access properties on the FilterBuilder
instance.
Name | Description |
---|---|
listen(event: string, callback: (filter: RangeFilterBuilder) => void) | Register a listener for a specific event. |
get() | Get the current range of the filter. |
set(range: [number, number] OR null, emitEvent: boolean) | Set the current range of the filter and optionally emit an event. |
reset(emitEvent?: boolean) | Reset the current filter to the initial values. |
setMin(value: number) | Set the minimum value. |
setMax(value: number) | Set the maximum value. |
getMinMax() | Returns the current min and max in an array. |
getStep() | Returns the number that specifies the granularity that the values must adhere to. |
filter() | Builds up the filter string from the current filter and it's children. |
getName() | Returns the name property of the filter. |
getGroup() | Returns the group property of the filter. |
getField() | Returns the field property of the filter. |
isAggregate() | Returns a boolean to indicate if the filter is using an aggregate. |
hasChanged() | Returns a boolean to indicate if the filter's current value differs from the initial value. |