Skip to main content

api.getValue()

Description

Gets the filter configuration object

Usage

api.getValue(): object;

Returns

The method returns an object that represents filtering rules, which includes:

  • glue - (required) the logic for combining filtering rules:
    • "and" - displays records that correspond to all rules at once
    • "or" - shows records that correspond to at least one of the rules
  • rules - (required) an array of filtering rules. It can be an individual rule or a group of rules. Each rule object has the following parameters:
    • field - (required) the id of a field. It should be the same as the corresponding field id of the fields property
    • type - (optional) filter type: "text" (default) | "number" | "date" | "tuple"
    • filter - (optional) the filter operator available for this type
    • value - (optional) the value in the field
    • includes - (optional) an array of the included values (strings, numbers or dates).

The rules object may also include the glue parameter and the rules object above.

Example

This example shows how to use the getValue() method of the FilterBuilder API to retrieve the current filtering configuration. When the user clicks the "Show value" button, the current filter (rules and groups) is fetched and logged to the console.

<script>
import { getData } from "../data";
import { FilterBuilder } from "wx-svelte-filter";
import { Button } from "wx-svelte-core";

const { value, fields, options } = getData();

let api = $state();

function logValue() {
console.log(api.getValue());
}
</script>

<Button type="secondary" onclick={logValue}>Log value</Button>
<FilterBuilder bind:this={api} {value} {fields} {options} />

Related articles: How to access FilterBuilder API