Column filters
Last updated
Was this helpful?
Last updated
Was this helpful?
A column-based filter allows you to filter dynamically, without modifying your original SQL query or resource, while fully leveraging your cloud data warehouse computing power.
You can think of column filters as WHERE clauses wrapping your CARTO + deck.gl source, widget or layer.
Typically, column-based filters originate from user inputs in the UI of your application, most commonly from CARTO Widgets (eg: clicking in a category of a filters the map for that category)
Filters are an object-type property that is accepted by:
...TableSource
and ...QuerySource
, for server-side filtering of both layers and widgets.
All , for client-side filtering of widgets when using ...TilesetSource
and rasterSource
,
, for client-side filtering of deck.gl layers.
If your application needs to manage different sets of filters, you can create as many filter objects as needed (myFiltersA
, myFiltersB
) and manage them independently.
To manage your filters, use any of the following functions
Adds a filter to a filter object.
column: STRING
the name of the column that this filter will be applied too
values: a set of values to filter. The expected format is dependant on the selected type
.
Removes all filters from a filter object that match that column (or column + owner).
column: STRING
all filters affecting this column will be removed (unless owner is specified)
owner: STRING
if specified, the removed filters will be only the ones matching exactly the column + owner combination.
Removes all filters from a filter object.
Returns all the current filters and its values
for a given filter inside a filter object.
column: STRING
the name of the column we're checking for filters
owner: STRING
if specified, this function will only check filters matching exactly the column + owner combination.
Returns a boolean: true
if there are already filters that match the specified properties, false
if there are no filters matching them.
column: STRING
the name of the column we're checking for filters
owner: STRING
if specified, this function will only check filters matching exactly the column + owner combination.
Usage
Values
FilterType.IN
number[] | string[]
Filter rows matching exactly these values. Example: ['Madrid', 'New York']
FilterType.BETWEEN
number[][]
Filter rows between those values. [a, b] both are included. Example: [[0, 300]]
FilterType.CLOSED_OPEN
number[][]
Filter rows between those values. [a, b) a is included, b is not. Example: [[0, 300]]
FilterType.TIME
number[][]
Similar to BETWEEN, but more suitable for date or timestamp columns. [a, b] both are included: ['964656085544', '1021247914455']
FilterType.STRING_SEARCH
string[]
Filter rows soft-matching these values. The results will be ordered with the exact matches first. Example: ['Madrid']
will also return rows with madrid
or Madrid Centro
filters: A valid Filters
object.
filtersLogicalOperator: Indicates whether filters
are applied following an AND
logic or an OR
logic. Must be a string 'and' | 'or'
.
Sometimes widgets are used to filter the data, for example, when clicking in a category or a pie sector. If the filter was also applied to the widget, the result could be undesired, as the widget itself would lose all the other values.
To prevent this, simply make sure to assign your widget an arbitrary string identifier via filterOwner and then use that same identifier in your addFilter calls.
Example of a filter not applying to a widget
In this example, all layers depending on data
would be filtered (therefore the map would be filtered) but the widget would still show all the categories, allowing for subsequent interactions.
type: FilterType
the filter operation. Check for a list of accepted values.
owner (Optional): STRING
this filter won't affect that have a matching filterOwner
property. Check .
This type contains the different filter types allowed in
Use this function to convert a valid set of filters into the properties expected by deck.gl to achieve GPU-based filtering (client-side filtering) of your CARTO + deck.gl layers. Useful when combined with .
fIlterSize: An integer 2, 3, or 4. Must match the filterSize
used to create the .