Available only in PRO Edition
Since 7.1
The widget is available in the Webix Pro edition.
Webix Filter is a handy interactive tool for filtering complex datasets. The Filter widget allows you to filter data, set the list of rules (depending on data type) or exclude some data from filtering.
webix.ui({
view:"filter",
mode:"text",
field:"title",
data: data,
on:{
onChange(){
const filter = this.getFilterFunction();
data.filter(obj => filter(obj));
}
}
});
Main properties:
"number"
by default);Related sample: Filter: Basic Initialization
The Filter widget contains three main UI-related elements:
The filtering rules are displayed in a combo box. Their list depends on the mode value:
the rules for the "number" mode
the rules for the "text" mode
for the "date" mode (displays datepicker or daterangepicker depending on the selected rule)
The "between"/"not between" filtering rules with its "daterangepicker" input will have the following UI:
The type of the entered value is defined by the field property and corresponds to the related item of the dataset. Filtering is performed according to the selected rule:
{
view:"filter",
mode:"number",
field:"year",
// ...
}
You can configure the look of items inside the multiselect list using the template property:
{
view:"filter",
mode:"number",
field:"year",
template:function(obj){
var value = obj.year;
var color = value >= 1980 ? "green" : "red";
return "<span style='color:"+color+"'>"+value+"</span>";
},
// ...
}
Related sample: Filter: Templates
To define your own set of filtering rules for the rule field, set the conditions property. You can change the existing set of rules or completely redefine them.
When changing filtering rules you can:
"greater", "less"
, etc);{
view:"filter",
mode:"number",
field:"rating",
conditions:[
// preset conditions and inputs
"equal", "contains",
// custom condition and input
{ id:"between", value:"Between", batch:"rangeslider", handler:function(a, b){
return a >= b[0] && a <= b[1];
}},
// label with static value - use view:"template"
{ id:"above", value:"Above", batch:"template", handler:function(a){
return a > 50;
}},
{ id:"below", value:"Below", batch:"template", handler:function(a){
return a <= 50;
}},
// no input - use batch:"none"
{ id:"top", value:"Top rated", batch:"none", handler:function(a){
return a <= 80;
}}
]
// ...
}
A custom filtering rule should contain the following properties:
The default inputs array can contain the following items:
inputs: [ "text", "datepicker", "daterangepicker", "none"];
If the above inputs are not enough, you can create custom ones and append them the array of preset inputs.
To create a custom input, you should:
view:"filter",
inputs: [
//preset inputs
"text", "none",
//custom input
{ view:"rangeslider", max:100, min:0, step:1, moveTitle:false, batch:"rangeslider",
on:{
onChange:function(){
const filter = this.queryView("filter", "parent");
filter.applyFilter();
}
}}
]
If you want a static label rather than an input control, use view:"template"
:
{
template:"some average value e.g. 50",
batch:"template",
borderless:true,
css:{"line-height":"28px"}
}
In the case when input is not needed, define input as "none"
.
Related sample: Filter: Custom Inputs
You can localize Filter according to the peculiarities of a certain language. By default en-US locale is used. Name of button and the rules of used filters are stored in the webix.i18n.filter object:
webix.i18n.filter = {
less: "less",
lessOrEqual: "less or equal",
greater: "greater",
greaterOrEqual: "greater or equal",
contains: "contains",
notContains: "not contains",
equal: "equal",
notEqual: "not equal",
beginsWith: "begins with",
notBeginsWith: "not begins with",
endsWith: "ends with",
notEndsWith: "not ends with",
between: "between",
notBetween: "not between"
};
There are 2 ways of applying a custom locale:
Apply the created locale with the help of the setLocale method.
More information about widget localization read in the related article.