# Sort a collection

> Learn how to sort the items of a Collection List in ascending or descending order by a criterion such as name or price, and let the user switch between several sorts with buttons and states.

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

**Sort the items in your collection in Ascending or Descending order based on the criterion of your choice (name, price, etc.).**

[Video: Real estate app: tapping the price button sorts the listings by price, then tapping the name button sorts them by name]

## Create a sort formula

1. Select your [Collection List](https://docs.pandasuite.com/essentials/data/collection/) and, in its properties, click **Sort**. The **Collection Sort** window lists the sorts of the collection.
2. Click **+**, then give the sort a **Name**, for example *Price ascending*. The name is required.
3. Under **Expressions**, click **Add**. Set **By** to the field to sort by, and **In order** to **Ascending** or **Descending**.
4. Click **Validate**.

[Image: Sort window of a Collection List of Paris places: the Sort by name formula on /fields/Name, in Ascending order, framed]

The first sort you create applies to the list right away. To apply another one, click **Sort**, then click its name in the list. Use the gear icon next to a sort to edit it, and the trash icon to delete it.

> **Tip**
>
> A sort can hold several expressions. The list is sorted by the first one; items with the same value are then sorted by the next one. For example, sort by category, then by name within each category.

## Let the user change the sort

A Collection List can hold several sort formulas, for example by price and by name, or by price in ascending and in descending order. To let the user switch from one to another with buttons, give each sort its own state.

1. [Create one sort formula](https://docs.pandasuite.com/essentials/data/sort-a-collection/#create-a-sort-formula) for each sort you want to offer.
2. Place the Collection List in a container with states: the screen itself, or a [Multi-state](https://docs.pandasuite.com/essentials/components/multi-state/) component. Create one [linked state](https://docs.pandasuite.com/essentials/interactions/understand-states/) per sort.
3. In each state, select the Collection List, click **Sort** and choose the formula for that state.
4. On each button, add a **Change screen state** action to the **Single tap/click** trigger, and choose the state that holds the button's sort. With a Multi-state, use **Interact with a component**, then **Change State**.

When the user taps a button, the list reorders according to the sort of the new state.

> **Tip**
>
> Since each sort has its own state, you can also change the look of the buttons in each state to show which sort is active.
