options
Description
Optional. An array of options or a function that receives field id and returns optionsRequired when a single field is specified at the initialization stage.
Usage
options?: any[];
| ((field: string) => AnyData[] | Promise<AnyData[]>) | any[];
Parameters
options - includes an array of options (string, number, date) to be used in filter. It can also be a function (async as well) that receives field id and returns options.
Example
<script>
import { getData } from "./common/data";
import { FilterBuilder } from "@svar-ui/svelte-filter";
const { values } = getData();
const options = { ["USA", "China", "Germany"]};
</script>
<FilterEditor field={"country"} {options} />
Options for a single field can be collected from data with the getOptions helper.
Options can be dynamic. If fields are defined, new options are loaded into the FilterEditor each time a field is selected in the UI. In this case options must be defined as a function:
<script>
import { getData } from "../data";
import { FilterEditor } from "@svar-ui/svelte-filter";
const { data, options, fields } = getData();
// retrieve options array for a single field out of options hash
function provideOptions(field) {
return options[field] || [];
}
</script>
<FilterEditor options={provideOptions} />
Related articles: FilterEditor Guide