add-rule
Description
Fires when adding a filtering ruleUsage
"add-rule": ({
rule: {
id?: string,
parent?: string,
data?: rule[],
glue?: "and" | "or",
field?: string,
$temp?: boolean,
type?: string,
predicate?: "month" | "year",
filter?: string,
includes?: any[],
value?: any,
};
edit?: boolean,
after: string | number
}) => void;
Parameters
Parameters
The callback of the action takes an object with the following parameters:
rule
- a filtering rule object with the following parameters:id
- (optional) the rule idparent
- (optional) parent id if anydata
- (optional) an array with therule
object parameters for each item$temp
- (optional) set to true by default, which means that a group is added only temporarily before changes are savedglue
- (optional) "and" | "or"field
- (optional) the id of a fieldtype
- (optional) the type of a value: "text" (default, for string values), "number", "date", "tuple"filter
- (optional) the filter operatorincludes
- (optional) an array of the included values (strings, numbers or dates)value
- (optional) the value passed to the field
edit
- (optional) by default, opens the filter rule editor when a group is added; if it's set to false, a group with an empty filter is added.after
- (optional) the id of a field after which a new group will be added
Example
The example below shows how to add a rule without opening the editor form and set the filtering value:
import { getData } from "./common/data";
import { FilterBuilder } from "@svar-ui/react-filter";
export default function Example() {
const { value, fields, options } = getData();
const init = (api) => {
api.intercept("add-rule", ev => {
ev.edit = false;
ev.rule.includes = ["Daisy"];
});
};
return (
`<FilterBuilder
value={value}
options={options}
fields={fields}
init={init}
/>`
);
}
Related articles: