Skip to main content

filter()

filters controls by some criteria

filter(rule?: function | object, config?: object): string;

Parameters:

  • rule: function | object - the filtering criteria
    • If set as a function, 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 true/false
    • If set as an object, the parameter has the following attributes:
      • by: string | number - required, the id of a column
      • match: string - required, a pattern to match
      • compare: 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 match
        • item - a data item the values of which should be compared (e.g. a row)
  • config: object - optional, defines the parameters of filtering. The parameter may contain the following properties:
    • type: string - optional, defines the area the filtering will be applied: "all", "level", "leafs"
    • level: number - optional, the level the filtering will be applied to
    • add: boolean - optional, defines whether each next filtering will be applied to the already filtered data (true), or to the initial data (false, default)
    • id: string - optional, the id of the filter
    • permanent: boolean - optional, true to make the current filter permanent. It will be applied even if the next filtering doesn't have the add:true property in its configuration object. Such a filter can be removed just with the resetFilter() method

Returns:

  • id: string - the id of the filter

Example

// filtering data by a function
tree.data.filter(function (item) {
return item.value.toLowerCase().indexOf("a") !== -1;
});

// filtering data by the column
treeGrid.data.filter({
by: "name",
match: "Angola"
});

Related sample: TreeGrid. Filter