Group Selector (aka List.Contains() No Results, or Having Trouble Checking the Contents of Lists?)

#1

I often find myself making tables with many groups.

Sometimes I want to implement the ability for visitors to my doc to be able to select specific groups without needing to know how to operate the Filter() function. To allow this I often implement a small selector table. (Here I’m indicating the visitor’s selection with column ‘x’.


This approach is especially useful when I have a complicated Filter running in addition to the Group selector.

You might think that all you have to do is check if the groups you are showing are in the group names you selected.

i.e.
Group.Contains(Selector.x)

What you’ll notice if you try this is that it doesn’t work :sweat_smile: :

This is because the Selector is wrapping the list of group names (“A” and “B”) in another list. This is really tricky to notice, because if you print Selector.x it looks like it’s a list of [A, B]:
image

If you don’t know this, when you check if Selector.x has “A” in it, it can get very confusing.

image

Wtf?
This is because a list doesn’t normally have brackets around it. When it does, it’s actually a list with a list inside of it.
image

This means that if you want to get the list inside of that list, you need to use First() to get the first (and in this case, only) element. Then the Contains() function will work as expected.
image

Changing the Filter to match fixes the issue; everything shows up!

And now the Selector will work as expected.

The completed table.

If you’d like to access the doc you can request access here

3 Likes

#2

Very helpful - thanks

1 Like

#3

Love this hack but this is one where we have something to help - a multi select control - unless I am missing something I think it will get the job done.

4 Likes

#4

Hahah wow. I’ve reinvented the wheel.

If I need to allow multiple selects in a table to affect the filter of another table, is this still a viable way to do it? Or is there a better way for that as well?

1 Like

#5

Suppose the keyword for the search varies and needs to be arbitrarily entered by the user/reader.

Assuming we do not want to reader to have to edit a Filter formula, am I correct that the original solution proposed here is needed and a multi-select control would not work?

1 Like

#6

Just shows the depth of your coda knowledge - you hacked controls!

Yes, this would work as long as the data type is the same - just have to keep @ref in mind.
Also to keep in mind is using a control to filter the table it is pulling the data from causes a gotcha - you filter out the values you want to list. So it is best to point the control to a table and use it to filter views.

Play around with it and happy to help.

1 Like

#7

The solution of the multi control would work as the user would just have to select the values for the filter in the select control. The filter in itself wouldn’t have to be written by the user, and the selectable items would be updated from the table by the Default values in the multi select menu.

2 Likes

#8

Thank you Tom - much appreciated

1 Like

#9

FYI @mallika,

When I come upon your responses in this forum where you have posted an image, the image does not appear. Attempts to open the image get this browser prompt:

This site can’t be reached

dha4w82d62smt.cloudfront.net ’s server IP address could not be found.

  • [Try running Windows Network Diagnostics](javascript:diagnoseErrors()).

DNS_PROBE_FINISHED_NXDOMAIN

1 Like

#10

Thanks for letting me know. I’ll look into this and see why Cloudfront is not responding!

1 Like

#11

Thanks for this explanation @cnr !!

It eliminates much confusion :crazy_face:!!

cc: @Karim_Noseir (I was mistaken about List() always rendering brackets.)

2 Likes