How to set default filter value through JSON meta data in superset

Viewed 2012

I have a dashboard on which one filter is there called "District" in which list of values are there like "1,2,3,etc". How can I select default filter, means when page is loaded that filter say "2 or 3" automatically selected through JSON metadata?

I seen the json meta data structure and default_filter was also there. But I don't know what to type in that so that default filter is selected automatically.

Below I am attaching image of my dashboard and json metadata as well.

json metadata

{
  "timed_refresh_immune_slices": [
    
  ],
  "expanded_slices": {
    
  },
  "refresh_frequency": 0,
  "default_filters": "{\"180\": {\"__time_range\": \"No filter\"}}",
  "filter_scopes": {
    "180": {
      "district_id": {
        "scope": [
          "ROOT_ID"
        ],
        "immune": [
          
        ]
      },
      "__time_range": {
        "scope": [
          "ROOT_ID"
        ],
        "immune": [
          
        ]
      }
    }
  }
}

enter image description here

2 Answers

The easier way to add default filter is by selecting the filter-apply the filter and Save As - Overwrite Dashboard.

Once that you overwrite the Dashboard the Json will be automatically updated. Modifying the JSON manually is more prune to errors.

You may achieve this on Superset by passing the following params in the URL of the superset dashboard

http://dashboard_url?preselect_filters={{"slice_id"}:{{"column_to_be_filtered"}: {"value_to_be_filtered"}}}

Determine the slice_id (i.e.viz filter box which needs to be filtered) by looking at its metadata in the edit mode of the chart. The column to be filtered is the actual column similar to the dataset and must pass the value in the URL according to need.

Related