Greg Rowles
Greg Rowles

Reputation: 341

urlParams (filters) not applied with superset-embedded-sdk

We're using @superset-ui/embedded-sdk to embed a single dashboard with 2 preconfigured filters on an external site. We recently upgraded to the v4.0.1 (to take advantage of urlParams for dynamic filtering):

enter image description here

However, we cannot get our dashboard to apply our 2 filters at runtime.

We've tried several variations on the urlParams but the result is always a loaded dashboard with no filters applied (users must manually set these filter values). Here is our code:

dashboardUiConfig: { 
  hideTitle: true, 
  hideTab: true, 
  hideChartControls: true, 
  filters: { 
    visible: false, 
    expanded: false
  },
  iframeTitle: false,
  urlParams: { level: 5, ou2: "Boston" }
}

Our embedded result is always loaded with none of the above filters applied:

enter image description here

Our superset_config.py config file had the following lines added for embedding to work:

WTF_CSRF_ENABLED = False

SESSION_COOKIE_SAMESITE = None

TALISMAN_ENABLED = False

Hoping this is something someone else has already encountered and figured out...

Having inspected the page after rendering, the following URL is present (I would've expected the urlParams to be nested :?)

enter image description here

Upvotes: 2

Views: 558

Answers (2)

Patrick
Patrick

Reputation: 81

  1. Make sure you have the ENABLE_TEMPLATE_PROCESSING feature flag enabled.
FEATURE_FLAGS = {
    "ENABLE_TEMPLATE_PROCESSING": True,
}
  1. Make sure pass the urlParam.
urlParams: {
    foo: 'bar',
}
  1. Make sure you use the macro in the sql for your dataset
select fld from tbl where fld= '{{ url_param('foo') }}'

Here's some useful documentation:

Also, you can add the following to your javascript to only set that url parameter if it is not none.

urlParams: {
    {% if foo is not None %}
    foo: '{{ foo }}',
    {% endif %}
}

Then, in the sql for your data set, you can limit the results by that field only if that field was set.

select old from tbl where true
{% if url_param('foo') %}
and foo = '{{ url_param('foo') }}'
{% endif %}

Upvotes: 1

agustin simonte
agustin simonte

Reputation: 1

If you want to use urlParams you have to modify your query. It doesn't work with normal filters. Your query would have to be something like

SELECT * FROM example E WHERE E.level = '{{ url_param('level') }}' AND E.ou2='{{ url_param('ou2') }}

Upvotes: 0

Related Questions