From e2332c964c6d5ae874b89350e58ae96e4de4c15e Mon Sep 17 00:00:00 2001 From: Anais Concepcion <69366135+anaisconce@users.noreply.github.com> Date: Tue, 30 Apr 2024 03:42:02 +0000 Subject: [PATCH] choice-filtering --- help/en/docs/col-refs.md | 14 ++++++++------ help/en/docs/col-types.md | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/help/en/docs/col-refs.md b/help/en/docs/col-refs.md index 704c77c80..7318c69e5 100644 --- a/help/en/docs/col-refs.md +++ b/help/en/docs/col-refs.md @@ -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. diff --git a/help/en/docs/col-types.md b/help/en/docs/col-types.md index 982e7087c..d544efb11 100644 --- a/help/en/docs/col-types.md +++ b/help/en/docs/col-types.md @@ -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