Skip to content

Commit

Permalink
Merge pull request #336 from gristlabs/choice-dropdown-filtering
Browse files Browse the repository at this point in the history
choice-filtering
  • Loading branch information
anaisconce authored Apr 30, 2024
2 parents f0c7229 + e2332c9 commit 9010314
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions help/en/docs/col-refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,36 +181,38 @@ We can see that the value in the Full Name column for the record with Row ID =`2

When entering data into a reference column you will see a dropdown list of all available values to choose from. Sometimes the list can get long, and in some cases confusing. For example, say you’re tracking population changes in the 1,000 most populous world cities. When entering a city into the reference column for city selection, the dropdown lists all 1,000 cities.

*![Unfiltered reference dropdown list](/images/filter-reference-columns/unfiltered-cities.png)*
*![Unfiltered reference dropdown list](images/filter-reference-columns/unfiltered-cities.png)*
{: .screenshot-half }

It would be useful if the dropdown list of city choices were filtered based on the country selected in the `Country` column.

To filter a reference column’s dropdown list, select the reference column then set a “Dropdown Condition“ in the Creator Panel under the "Column" tab.

*![Set dropdown condition](/images/filter-reference-columns/set-dropdown-condition.png)*
*![Set dropdown condition](images/filter-reference-columns/set-dropdown-condition.png)*
{: .screenshot-half }


You can filter a dropdown’s choice by writing a condition as a formula. The attribute `choice` refers to choices in the dropdown. In this case the formula is `choice.Country == $Country`.

*![Reference dropdown filter condition](/images/filter-reference-columns/city-filter-condition.png)*
*![Reference dropdown filter condition](images/filter-reference-columns/city-filter-condition.png)*
{: .screenshot-half }

*![Filtered reference dropdown list](/images/filter-reference-columns/filtered-cities.png)*
*![Filtered reference dropdown list](images/filter-reference-columns/filtered-cities.png)*
{: .screenshot-half }


Why did that work? The city column is a reference column pointing to a `Cities` table that matches countries and cities. That table looks like this.

*![Cities reference table](/images/filter-reference-columns/cities-tables.png)*
*![Cities reference table](images/filter-reference-columns/cities-tables.png)*
{: .screenshot-half }

The formula condition `choice.Country == $Country` is looking up each choice’s country in the `Cities` table using a [reference lookup](https://support.getgrist.com/references-lookups/#reference-columns-and-dot-notation), then it compares those countries to the value entered in the `Country` column of the `Population Rankings` table.

*![Filtered reference dropdown list](/images/filter-reference-columns/filtered-cities-highlight.png)*
*![Filtered reference dropdown list](images/filter-reference-columns/filtered-cities-highlight.png)*
{: .screenshot-half }

The dropdown now lists only choices (aka cities) whose country equals the country entered in `Country` column.

The `choice` attribute can also be used when setting dropdown filter conditions for [Choice](col-types.md#choice-columns) and [Choice List](col-types.md#choice-list-columns) columns.

Note that because reference dropdown filtering is written as formulas, filtering can be very flexible and granular. Users experienced with [access rules](https://support.getgrist.com/access-rules/) may notice similarities in how to think about writing these formulas.
3 changes: 3 additions & 0 deletions help/en/docs/col-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ while the cell is being edited. You can also use the arrow keys and the
`Delete` key to navigate and delete choices, or simply click the delete icon
when hovering your cursor over a choice.

!!! note "Filtering Choice and Choice List columns' dropdown lists"
When entering data into a Choice or Choice List column you will see a dropdown list of all available choices. Sometimes it would be useful to filter the dropdown list based on a condition, such as the value in another cell. Writing conditions to filter choice dropdown lists is similar to [filtering reference column's dropdown lists](col-refs.md#filtering-reference-choices-in-dropdown).

## Reference columns

This sets up a cross-reference to another table. You can specify the
Expand Down

0 comments on commit 9010314

Please sign in to comment.