filter()
filters data items in a component
filter(rule?: function | object, config?: object, silent?: boolean): string;
Parameters:
rule?: function | object- optional, the filtering criteria- If set as a function, filtering will be applied by the rule specified in the function. It takes as a parameter a data item and returns true/false
- If set as an object, the parameter has the following attributes:
by?: string | number- optional, the id of a data fieldmatch?: string- optional, a pattern to matchcompare?: function- optional, a function for extended filtering that takes the following parameters:value- the value to comparematch- a pattern to matchitem- a data item the values of which should be compared
config?: object- optional, an object with the following properties:id?: string- optional, the id of the filteradd?: boolean- optional, defines whether each next filtering will be applied to the already filtered data (true), or to the initial data (false, default)permanent?: boolean- optional, true to make the current filter permanent. It will be applied even if the next filtering doesn't have theadd:trueproperty in its configuration object. Such a filter can be removed just with the resetFilter() method
silent?: boolean- optional, if set to true, the method will be called without triggering events, false by default
info
Note that after calling the method with the silent:true parameter, you may need to repaint the component with the paint() method.
Returns:
id: string- the id of the filter
Example
// filtering data by a function
grid.data.filter(function (item) {
return item.a > 0 && item.b !== "Apple";
});
// or
grid.data.filter(function (item) {
return item.a > 0 && item.b !== "Apple";
}, {
add: true,
});
// filtering data by the column
grid.data.filter({
by: "a",
match: "Orange",
compare: function (value, match, item) {
if (item.a !== "Some") {
return val === "New";
}
return false;
}
}, {
add: true,
});
Related sample: Data. Filter