Filtering

Problem

How to filter dataset?

Solution

The library provides ability to filter data by one or several criteria (applicable to all the components that operate on data).
To filter dataset you need to call the filter() method. Each time the method is called, all data is re-filtered (previous results aren't preserved).

It's possible to call the filter() method in two modes:

  1. filter(property,value)
    This approach is used for 'contain' filtering. It is simple, but isn't flexible. The method shows items where 'property' (the first parameter) contains 'value' (the second parameter). Such filtering isn't case-sensitive:

    $$("mylist").filter("#year#","2010");
  2. filter(function)
    Using a function as a parameter allows to define different filter rules and to filter by multiple properties. Filtering function is called for each object of the dataset, and if it returns true, the object will be displayed:

    $$("grid").filter(function(obj){
            if (obj.sales > 10 && obj.company == "Company 3") return true;
            return false;
    })

Related sample: 04_list/12_filtration.html