I'm building an app where if you select a user from a table, then information about that user appears in a table below. One user can have multiple wallet addresses. I want to create a script that counts the number of wallets that a user has and have the number appear in this field.
Hey @Anthony_Gray,
There's 3 ways to go about it, you can create a query to retrieve that information, for instance:
select * from users where id = {{table3.selectedSourceRow.id}}
Or, if you are pulling that information in the query that feeds the table, you can reference it directly:
{{table3.selectedSourceRow.count}}
If you want to display the number of selected rows, you can activate it on the table settings and then use:
{{table3.selectedRows.length}}
Let me know if this helps!
When I use {{table3.selectedSourceRow.count}}, nothing returns. I calculated the number of wallets each user has in a separate query. Is it possible to use JS to compare this separate query with the selected rows in table3?
Sorry, I meant table3.selectedSourceRows.length. This only works if you have multiple row selection enabled.
You can run the JS query off of the selected row by matching ids, for example:
table3.selectedSourceRow.id and then comparing that id with your metrics.
If this doesn't work, can you send a screenshot of the query?
Still having trouble here. Basically when I select a row here, I want to count all the addresses associated with the user. In the image you can see there are two addresses associated with this user. I want the number '2' to appear here.
I wrote this query that counts the number of wallets each user has but I don't know how to connect it to the table in the image
--This query counts the number of wallets associated with one profile--
WITH walletz AS (
SELECT
wallets."address",
wallets."provider",
profiles."display_username",
profiles."display_name"
FROM
SHARE."profiles" AS profiles
JOIN SHARE."wallets" AS wallets ON profiles."id" = wallets."owner_profile"
)
SELECT
display_username,
COUNT(DISTINCT "address") AS address_count
FROM
walletz
GROUP BY
display_username
ORDER BY
display_username;
To link the 2 you can use JS, like this:
**Sibling wallets: {{ formatDataAsArray(wallet_query.data).find(x => x.display_username == table3.selectedRow.display_username).count }}**
Place this code on the text for the sibling wallets.
Something like this should work. Replace wallet_query with the name of your query.
I appreciate your help here! I tried that query and it doesn't return a value.
The names of the columns and sql query match. Should this JS query reference wallet_count in the sql query?
Just change count (at the end) for address_count and it should give you the correct value