# How to filter items by “choice” component

**URL:** <https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122>\
**Category:** Ask for Help\
**Created:** [September 22, 2021, 6:34am UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122 "2021-09-22T06:34:02Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slade\_Rose](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slade_rose/32/15309_2.png) [@Slade\_Rose](https://community.glideapps.com/u/Slade_Rose)\
**Post date:** [September 22, 2021, 6:34am UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/1 "2021-09-22T06:34:02Z")

</div>

I have a list of sites, across several countries, that I display in a list. I want to be able to filter and only show the sites for the country that the user is currently in.

1. Is there a way I can do this automatically by getting the user’s location/IP and matching it to the country?

2. How would I do this with the choice component?

3. If I had to ask the user for their country, is there a way I could store it so that I wouldn’t have to ask them again?

Thank you so much in advance for all and any answers!

---

<div class="post-metadata">

**Author:** ![AyS\_0908](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ays_0908/32/27349_2.png) [@AyS\_0908](https://community.glideapps.com/u/AyS_0908)\
**Post date:** [September 22, 2021, 7:15am UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/2 "2021-09-22T07:15:39Z")

</div>

Hi,

1. No idea

2. Here, your best friend should be the filter on the choice components.

- 2 columns : Country with sites in front of each country
- 2 choice components: first with source value “country”, and second “sites”
- On the “sites” choice component, apply a filter on “country” is “screen \> country” (which means the list of sites will be restricted to the country selected in the screen).

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/4/741997472f67cd25f4fd3b52d6d863ca717df4f8.png)

1. You need to use the user profile

- A dedicated tab, with at least Name, Email, Picture + in your case “Country”, “Sites”
- In the User section on your app (top of the hamburger menu), make sure that the fields match on the right part of the screen
- Then add components to collect the information: name etc + the 2 choice components mentioned above

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/8/5/85b2f7b07527b5f9f6d21e4b4774625d10d0ac08.png)

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/d/ad75d7beb97b1452d9f7613bff49aa9b6c5dd63c.png)

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [September 22, 2021, 8:44am UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/3 "2021-09-22T08:44:48Z")

</div>

> [@Slade\_Rose](#):
>
> - Is there a way I can do this automatically by getting the user’s location/IP and matching it to the country?

There are some APIs that supports this, but I haven’t tried this with the Experimental Code column so I’m not sure it will work.

I think you’d better follow @AyS_0908’s guide. Basically ask for the user’s country in the onboarding process and filter your sites accordingly.

---

<div class="post-metadata">

**Author:** ![Slade\_Rose](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slade_rose/32/15309_2.png) [@Slade\_Rose](https://community.glideapps.com/u/Slade_Rose)\
**Post date:** [September 22, 2021, 10:35am UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/4 "2021-09-22T10:35:06Z")

</div>

Hi, thank you so much for your reply.

So the one caveat for this app is that it is a public app. There are no user accounts and we don’t want to store user info or ask them to sign up.

Is there a way we could use one choice component to ask a user what country they are in, and then show them a list of all the sites that have the same country?

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [September 22, 2021, 10:40am UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/5 "2021-09-22T10:40:10Z")

</div>

You can add a text component/choice component pointing to a user-specific column, then filter based on that column.

---

<div class="post-metadata">

**Author:** ![Slade\_Rose](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slade_rose/32/15309_2.png) [@Slade\_Rose](https://community.glideapps.com/u/Slade_Rose)\
**Post date:** [September 22, 2021, 11:30am UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/6 "2021-09-22T11:30:33Z")

</div>

Could you please assist me here? I have a choice component and the sites below. How would I apply the filter properly?

 ![Screenshot 2021-09-22 at 13.27.02](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/6/161c85ca1e47f1633a6ae012e08973c68897f6ba.jpeg)  
 ![Screenshot 2021-09-22 at 13.28.23](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/c/7c989be3af434b8070ffd06785dfc38195a66ce1.jpeg)

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [September 22, 2021, 11:38am UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/7 "2021-09-22T11:38:44Z")

</div>

The filter should be something like:

Site\_country\_name is screen’s site\_country\_name\_user\_input. Assuming you’re letting the user write to the input column, and you have a column name in the sheet where you are storing sites.

---

<div class="post-metadata">

**Author:** ![Slade\_Rose](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slade_rose/32/15309_2.png) [@Slade\_Rose](https://community.glideapps.com/u/Slade_Rose)\
**Post date:** [September 22, 2021, 11:43am UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/8 "2021-09-22T11:43:09Z")

</div>

Yeah I’m not letting the user write to anything. I want to display a list of sites based on the country a user picks. The user then clicks on a row in the list that opens a link.

So, I want to filter a list of predetermined sites based on a list of predetermined countries that said sites exist in.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [September 22, 2021, 12:18pm UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/9 "2021-09-22T12:18:48Z")

</div>

> [@Slade\_Rose](#):
>
> I want to display a list of sites based on the country a user picks.

You must let the user write that choice to a column before being able to filter anything, like I said above.

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [September 22, 2021, 12:28pm UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/10 "2021-09-22T12:28:48Z")

</div>

Hola,

I found a script days ago which finds the user’s IP address and its location and I think it can help you.

Unfortunately I didn’t test it but I am going to search it again and test it to know if we can use it in an Experimental Column.

I let you know in the afternoon!

Saludos

---

<div class="post-metadata">

**Author:** ![Slade\_Rose](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slade_rose/32/15309_2.png) [@Slade\_Rose](https://community.glideapps.com/u/Slade_Rose)\
**Post date:** [September 22, 2021, 1:33pm UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/11 "2021-09-22T13:33:58Z")

</div>

Thanks very much, I look forward to hearing back from you!

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [September 22, 2021, 3:54pm UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/12 "2021-09-22T15:54:31Z")

</div>

Hola de nuevo!

You need to follow these steps: 🙂

1- Use this URL to get the user’s IP and country [https://api.country.is/](https://api.country.is/)

You will see something like:

> {“country”:“VE”,“ip”:“190.39.04.102”}

2- Create a new Experimental Column using this repl created by Mark Probst: [https://glide-yes-code-hell-yes.markprobst.repl.co](https://glide-yes-code-hell-yes.markprobst.repl.co) and put the following code:

```auto
const data = await fetch(`https://api.country.is`)
const json = await data.json();
return json.country

```

your screen should look like this but showing your right country code instead:

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/8/c/8cf891299674e2cae9f7902cb06b97b8449bab0d.png)

I’m in Venezuela so my code is shown as **VE**.

I hope it helps you @Slade_Rose

Saludos

---

<div class="post-metadata">

**Author:** ![Slade\_Rose](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slade_rose/32/15309_2.png) [@Slade\_Rose](https://community.glideapps.com/u/Slade_Rose)\
**Post date:** [September 22, 2021, 6:24pm UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/13 "2021-09-22T18:24:00Z")

</div>

Thank you so much! This was such a great and simple solution to the problem. Thank you!

---

<div class="post-metadata">

**Author:** ![Filo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/filo/32/43977_2.png) [@Filo](https://community.glideapps.com/u/Filo)\
**Post date:** [July 7, 2022, 5:48pm UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/14 "2022-07-07T17:48:36Z")

</div>

Hi @Slade_Rose ,  
I am having the same issue. The choice is predeterminated and I just want filter the list below according to the choice of the user.

I don’t know why we need to “write to”

Did you solve this?

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [July 8, 2022, 1:09am UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/15 "2022-07-08T01:09:35Z")

</div>

A choice component needs a place in your database to store the choice of the user. You can just add a user-specific column in the table that you built your screen on to do this.

Then, filter the inline list based on the chosen value.

---

<div class="post-metadata">

**Author:** ![Filo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/filo/32/43977_2.png) [@Filo](https://community.glideapps.com/u/Filo)\
**Post date:** [July 11, 2022, 2:23pm UTC](https://community.glideapps.com/t/how-to-filter-items-by-choice-component/32122/16 "2022-07-11T14:23:46Z")

</div>

Solved! Many thanks
