You can set the value through the related property in the configuration object or by changing it through the component state:
Initial value
view:"query",
value:{
"glue": "or",
"rules": [
{
"field": "first_name",
"includes": [
"Diana"
]
},
{
"glue": "and",
"rules": [
{
"field": "age",
"condition": {
"type": "less",
"filter": 45
}
}
]
}
]
}
Related sample: Query: Initialization
The value object contains the following properties:
Query value is a specific reactive propery, which means that developers can get and set its value as well as listen to its changes through the components state:
To get the value property call the getState() method and then access the "value" property of the resulting object:
$$("query").getState().value; // an object with filtering rules or null
Listening to Changes
To track value changes, you need to use the $observe handler of the component state:
$$("query").getState().$observe("value", function(value){
// custom logic
});
Related sample: Query: Listening to Changes
Additionally, you can use $observe in tandem with the onInit handler. The code inside the handler will be executed before the initialization of a widget:
webix.ui({
view: "query",
fields: [ /*fields for filtering*/ ],
value: { /*filtering rules and fields combinations*/ },
on: {
onInit: function() {
// "this" points to the widget
this.getState().$observe("value", function(value){
// custom logic
});
}
}
});
It can be useful when using Query to filter datasets.
To use Query for filtering datasets you need to get its helper function that implements the filtering logic. It can be done with the help of the getFilterFunction() method:
$$("query").getFilterFunction();
The method returns a "helper" function that combines all the defined filtering rules.
You can pass the helper function as a parameter to the filter method of Webix data components to iterate their items and check whether they correspond to the filter rules:
webix.ui({
view: "query",
on: {
onChange() {
const filter = this.getFilterFunction();
// data-widget to filter data in
$$("data-widget").filter(filter);
}
}
});
Related sample: Query: Filtering Data
Back to top