filter()
filters data items in a component
filter(rule?: function | object, config?: object): void;
Parameters:
rule: function | object
- the filtering criteria- If set as a function, the filtering will be applied by the rule specified in the function. The function takes an object of a data item as a parameter and returns an object with a filtering rule
- If set as an object, the parameter has the following attributes:
by: string | number
- mandatory, the id of a data field (the column of Grid)match: string
- mandatory, a pattern to matchcompare: function
- optional, a function for extended filtering that takes three parameters:value
- the value to compare (e.g. a column in a row for Grid)match
- a pattern to matchitem
- a data item the values of which should be compared (e.g. a row)
config: object
- optional, defines the parameters of filtering. It may contain two properties:add: boolean
- defines whether each next filtering will be applied to the already filtered data (true), or to the initial data (false, default)smartFilter: boolean
defines whether a filtering rule will be applied after adding and editing items of the collection
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,
smartFilter: 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,
smartFilter: true
});
Related sample: Data. Filter
Calling the filter() method without parameters reverts the component to the initial state:
grid.data.filter();