Reputation: 1601
I have created a visualisation in Apache Superset based on a Saved Query. How can I update the query based on the values filtered within a Filter Box?
I have experimented with Jinja and managed to pass hardcoded variables to my query through the template parameters. Now I just need to connect Jinja to the Filter Box such that the values are obtained through the filter rather than hard coded.
Upvotes: 5
Views: 7508
Reputation: 411
I discovered that this is possible using the filter_values
function that is added to the Jinja context via this file: https://github.com/apache/superset/blob/master/superset/jinja_context.py
The example in that file shows how one can build a templated query that pulls values from a filter box:
SELECT action, count(*) as times
FROM logs
WHERE action in ( {{ "'" + "','".join(filter_values('action_type')) + "'" }} )
GROUP BY action
So if you have a filter box for selecting values for action_type
, those values will be returned by filter_values
.
Upvotes: 6
Reputation: 11
The column name used in the filter should be the same in another table also. Have you tried it? If column names are different then create a materialized view with the changed column name or rename the column in the table itself
Upvotes: 1