Skip to content

How to use Jinja template for "Inverse Selection" filter type #34372

Answered by dosubot bot
natcharam asked this question in Q&A / Help
Discussion options

You must be logged in to vote

Hi @natcharam! I'm Dosu and I’m helping the superset team.

To handle both normal and "Inverse Selection" filters for the same column in a Jinja template, use the get_filters() macro instead of filter_values(). The get_filters() macro exposes the filter operator (IN or NOT IN), so you can generate the correct SQL logic for each filter type. Here’s how you can do it:

{% for filter in get_filters('CAMPAIGN_GROUP') %}
  {% if filter.op == 'IN' %}
    AND CAMPAIGN_GROUP IN ({{ "'" + "', '".join(filter.val) + "'" }})
  {% elif filter.op == 'NOT IN' %}
    AND CAMPAIGN_GROUP NOT IN ({{ "'" + "', '".join(filter.val) + "'" }})
  {% endif %}
{% endfor %}

This approach works because get_filters() r…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by natcharam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant