Skip to main content
Version: Next

List View Search and Filters

The filter bar of a ListView page (Charts, Dashboards, Users, Row Level Security and so on) offers two different things, and each page decides which of them it needs.

  • Global search is the always-visible search box at the start of the bar. One term finds a record when it appears in any of several text columns, the way the Charts search finds a chart by its name, description, type or dataset.
  • Field filters are the compact pills next to it. Each one is labelled with the field it narrows, and holds an explicit condition on that field: an option list, a date range, a number range or a text input.

Add it when people look records up by what they remember of them: a name, an email, part of a description. Users, Groups, Charts and Dashboards all work this way.

Leave it out when the useful fields are identifiers, numbers or structured data that people filter on deliberately. The Action Log has no global search: its dashboard ID, duration and JSON fields are each a field pill instead. Do not promote one field to the search box just because it comes first, since nothing on the page tells the user which field the box searches.

Semantics​

  • Global search matches the term case-insensitively as a substring of any searchable column (OR across columns). With BaseAllTextFilter (see below), surrounding whitespace is trimmed, a blank term does not filter, and %, _ and \ match literally.
  • The global search, every field filter and the API's base_filters are combined with AND, so search never widens what a user is allowed to see.
  • All of it runs in the database query behind the paginated list endpoint. The frontend never filters the rows it has loaded, and changing the search or a filter goes back to the first page.
  • The search box and each pill clear independently, and Clear all resets every one of them.

Backend: define the searchable columns​

The searchable columns are fixed on the server, never sent by the client. Subclass BaseAllTextFilter from superset/utils/filters.py, give it an arg_name, and return the columns from get_columns:

from superset.utils.filters import BaseAllTextFilter


class GroupAllTextFilter(BaseAllTextFilter):
arg_name = "group_all_text"

def get_columns(self) -> list[ColumnElement[Any]]:
return [Group.name, Group.label, Group.description]

Then register it in the REST API's search_filters, under a column that is already in search_columns:

class SupersetGroupApi(GroupApi):
search_filters = {"name": [GroupAllTextFilter]}

Flask-AppBuilder resolves {"col": "name", "opr": "group_all_text", "value": "..."} to the filter and rejects columns the API does not list in search_columns. Return columns of the listed model itself: a column reached through a to-many relationship would repeat a row once for every related item that matches.

Several older resources (chart_all_text, title_or_slug, css_template_all_text and others) predate BaseAllTextFilter and implement BaseFilter directly. They also OR an ILIKE across their columns, but they neither trim the term nor escape LIKE characters, so _ or % in their search acts as a wildcard. Use BaseAllTextFilter for new resources.

Frontend: configure the filter bar​

Add the all-text operator to ListViewFilterOperator in src/components/ListView/types.ts, then declare the filters on the page. The input of each filter decides how it is presented.

const filters: ListViewFilters = [
{
Header: t('Search'),
key: 'search',
id: 'name',
input: 'search',
operator: ListViewFilterOperator.GroupAllText,
placeholder: t('Search groups'),
toolTipDescription: t('Searches name, label and description'),
},
{
Header: t('Roles'),
key: 'roles',
id: 'roles',
input: 'select',
operator: ListViewFilterOperator.RelationManyMany,
selects: roleOptions,
},
];
  • input: 'search' is the global search box. Use at most one per page, with an all-text operator. The bar hides its label to stay compact, so Header becomes the input's accessible name, placeholder says what is being searched (keep it short: the box is 176px wide), and toolTipDescription lists the columns in an info icon inside the box.
  • input: 'text' is a free-text condition on a single field, rendered as a pill labelled with Header. Use it for fields that should not be part of the global search, such as IDs. Add numeric: true when the field is an integer column: the input then takes digits only, because the API reads any other text as "no value" and returns the rows where the column is empty.
  • input: 'select', 'datetime_range' and 'numerical_range' are the other field pills.

The filter bar always places the global search first, whatever the declaration order. If a page declares a second search filter, it is rendered as a pill rather than dropped.

Checklist for a new list view​

  1. Decide whether people look the records up by text. If not, use field pills only.
  2. If they do, write a BaseAllTextFilter subclass listing the columns, and register it in the API's search_filters.
  3. Add the operator to ListViewFilterOperator and declare one search filter with placeholder and toolTipDescription.
  4. Declare a field pill for every other condition people need.
  5. Test the filter class against each column, and the list endpoint with the search combined with a field filter and with pagination.