# Filter a collection

> Learn how to create custom filters for collections to facilitate user access to specific data in PandaSuite, including examples like the Paris City Guide application. Understand how to use conditions and variables to display filtered content effectively.

https://docs.pandasuite.com/essentials/data/filter-a-collection/

**Create custom filters to make it easier for the user to access certain data. Filters allow you to display the data in your collection based on a condition.**

Concretely, these filters act on the content of the component **Collection / List**: they allow displaying only the elements that meet a condition. This condition is freely determined. Each element is evaluated according to this condition and is displayed only if the condition is met.

In the Paris City Guide application, the user has the option to filter the list of good deals by category: *Food*, *Drinks*, *Museum* or *Outdoor*.

[Video: Paris City Guide on a phone: tapping the Food, Drinks or Museum category shows only the good deals of that category]

## Display categories

Visually display the categories that the user can select. The content of the collection adjusts according to the user's selection. In this example, the user clicks on Food and only displays the deals in that category.

Choose the design of your choice (below buttons).

[Image: Food, Drinks and Museum buttons above the Paris list: the Food state of the categories Multi-state and its highlighted button are framed]

Create a **Text** property (it's called *selected\_category* in the example below) in a [Datastore](https://docs.pandasuite.com/essentials/data/datastore/): this variable allows you to save the selected category so you can use it when creating the filter condition.

[Image: Datastore of the project: the selected_category text property is framed, below favorites, selected and selected_arrondissement]

When the user selects one of the categories, change the value of this variable.

Add an action: **Interact with a data source** → your Datastore → **Create/Update Data (Local)**, with ***selected\_category*** as the **Target** and the **Set** function.

Set its value manually. Below the user has selected the category *Food*, the value entered is *Food*.

[Video: on the Food button, Single tap/click, Interact with a data source, the Datastore, Create/Update Data on selected_category, value Food]

Now create the [condition](https://docs.pandasuite.com/essentials/components/condition/) that displays items based on the selected category.

In our example for a good plan to be displayed, the filter condition must be met. This one is composed of 2 expressions:

- If the user has not selected a category (the value of the variable *selected\_category* is unknown or empty\_)
- *OR* if the user-selected category (the value of the variable *selected\_category*) matches the category of the current element

Go to the properties of your component [Collection/List](https://docs.pandasuite.com/essentials/data/collection/). Click **Filter** and the **+** button;

[Video: Filter by Category condition of the Collection List: selected_category is unknown or empty OR the Category equals selected_category]

> **Tip**
>
> A filter is a single condition, so it uses one operator (**AND** or **OR**) for all its expressions. To combine several criteria with both **AND** and **OR** (for example, restrict the list to a category and also match one of several optional filters), compose multiple conditions as shown in [Mixing AND and OR](https://docs.pandasuite.com/essentials/components/condition/#mixing-and-and-or).

## Multi-selection of filters

In the previous example, the user can only select one category at a time. Therefore, the variable is of type **Text**.

If you want the user to be able to select more than one, you need to choose a different type of variable: **Array**. Indeed the table allows you to add one or more selected categories.

At the level of your filter condition, you need to adapt your expression:

- If the user did not select a category (the value of the variable *selected\_category* is unknown or empty\_)
- *OR* if the user selected category table contains the category of the current item

## Filter without user selection

In the previous examples, the filter was tied to a user selection. Nevertheless, this is not a requirement.

For example, you can choose to display only restaurants. In which case the filter condition becomes: if the category of the current item is *Food*.

[Image: Only display Food filter condition of the Collection List: the Category of the current item is equal to the text Food]

> **Info**
>
> If your database is on Airtable, you can also create server-side filters directly from the API. We recommend checking out this article: [Connect to Airtable](https://docs.pandasuite.com/essentials/integrations/connect-to-airtable/).

[Template: Paris City Guide with Favorites](https://pandasuite.com/templates/paris-city-guide/)
