filter

filters data items in a component

void filter(object|function rule, [object config] );

Parameters

ruleobject|functionthe filtering criteria
configobjectoptional, defines the parameters of filtering

Example

// prefiltering grid before using separate filters for columns
grid.data.filter((item)=>{item.b>43&&item.a!=="Some"});
 
// filtering the "b" column by value "Tyro"
grid.data.filter({ by:"b", match:"Tyro" });
 
// filtering data by several criteria at once
grid.data.filter({
    by:"b",
    compare:function(val,match,item){
        if(item.a!=="Some"){
            return val === "New"
        }
        return false;
    }
});

Details

The rule parameter:

1) if set as an object has the following attributes:

  • by - (string) mandatory, the id of a data field (the column of Grid)
  • match - (string) mandatory, a pattern to match
  • compare - (function) 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)

2) if set as a filtering function the rule parameter sets a "global" filter for data before applying "local" filters. It takes as a parameter a data item (e.g. a row) and returns an object with a filtering rule. Works all the time, unless redefined by a different global filter or removed.

The config parameter 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)
  • multiple - (boolean) defines whether a filtering rule will be added to the already applied filters (true, default), or previous filters should be removed in advance (false)

Reverting to the initial state

The method will render only the items that meet the filtering criteria. To revert the component to the initial state, call the filter() method without parameters.

grid.data.filter();
Back to top