api.exec()
Description
Allows triggering the FilterBuilder actionsUsage
api.exec(
action: string,
config: object
): void;
Parameters
action
- (required) an action to be firedconfig
- (required) the config object with parameters (see the action to be fired)
Actions
info
The full list of the FilterBuilder actions can be found here
Example
import { useRef } from "react";
import { getData } from "./common/data";
import { FilterBuilder } from "@svar-ui/react-filter";
import { Button } from "@svar-ui/react-core";
export function Example() {
const { value, fields, options } = getData();
const execAddRuleRef = useRef(null);
const init = (api) => {
execAddRuleRef.current = () => {
api.exec("add-rule", {
rule: {
field: "name",
type: "text",
includes: ["Daisy"],
},
edit: false,
});
};
};
return (
<>
`<Button type="primary" onClick={() =>` execAddRuleRef.current?.()}>
Add Rule
</Button>
`<FilterBuilder value={value} fields={fields} options={options} init={init} />`
</>
);
}
Related articles: