Skip to content

Static Filters

Common filters are usually handled (added, modified or removed) by the Filter Control or by any direct user interaction.

Sometimes we may need some unmutable filters that always filter the visualization and will never be modified by any action, for example if we want to exclude permanently a value from a visual when this queries the server.

That's when we can use the static filters:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
let attr = cf.Attribute('venuecity')
            .limit(10)
            .sort('asc', 'venuecity')
let static = cf.Filter('venuecity')
                .operation('NOT IN')
                .value(['Los Angeles'])
let myChart = cf.provider('Elasticsearch')
                .source('ticket_sales')
                .groupby(...)

                // Here is how static filters are specified
                .staticFilters(static)
                ...
myChart.execute()

Static filters should be specified only at definition time since they are not meant to be changed.

In the previous example, we are querying the top 10 venuecities but excluding always the city of Los Angeles. This way we also make sure that if we use any other filter over this visual Los Angeles will never come within the results.

It is important to mention that for a visual with static filters, if a normal filter is applied and this one matches any static filter in the field name and the operation, the static filter will be ignored in favor of the normal filter.

So using the same example:

1
2
3
4
5
let newFilter = cf.Filter('venuecity')
                .operation('NOT IN')
                .value(['New York'])

myChart.filters(newFilter).execute();

This will use the new filter over the static filter. The static filter however will remain stored by the visual and will be used again as soon as newFilter is removed.