How to return only the keys of entries with a true value in addon?
![James Cowen](https://us.v-cdn.net/6037124/user_avatars/4497106.jpg)
I have a table for my members called "nodes". It has an addon of "skills". The skills table is full of skills that are all bools. The two tables are linked by a shared id.
On my frontend I want to filter by a skill. So if I pick "Animation" from my UI filter select, it should search Xano and return the users who have ticked true to "Animation".
I've been doing the filtering on the frontend which I want to change.
Below is how I am doing it on the front end. ChatGPT may have helped with the JS ;)
Having a hard time trying to work this out in my function stack.
"for (let i = 0; i < artists.length; i++) {
let trueSkills = Object.keys(artists[i].skills).filter(skill => artists[i].skills[skill] === true);
artists[i].skills = trueSkills;
}"
TIA
Comments
-
Hi @James Cowen if I'm following correctly then you have a couple of different options here:
- Use a Join to so you can filter the main query
Joining nodes with skills will allow you to access the fields in skill in the by custom query section
Or
2. Flip the query so you can have the parent query be Skills and the child query be nodes
This will allow you to filter skills and return the nodes that match the parent results - Use a Join to so you can filter the main query
-
Hi @Michael Udinski
Thanks for the reply. I understand those two approaches.
What I can't figure out tho is how to return only true items from my table based on the search string.
Using "software" instead of "skills" as an example:
This is my text input:this is my "software" table, where every field/column is a bool (except for the id of course):
How can I customise the enquiry to search across the entire table with my input, which wants an object not a text input?
TIA
-
So filtering records works slightly differently. You don't need to define the field in your inputs but rather the field is defined on the left side of the expression builder coming from the database table
Your input will want to be of the value type that the field is. So in your case, a boolean instead of text. If you input a value of true, you get all records where software.Maya = true, if you input false, you get all the records where software.Maya = false.
Here's an example to follow along: -
thx Michael Udinski
…but that's static. I don't know what the user will enter, so I don't know what field to choose on the left. That needs to be dynamic.Below is my frontend filter. The visitor chooses which of my 200 members it wants to filter. If they choose they only want to see users who use Maya, I need to filter my 200 members by those that have Maya == true in my "software" table. But then the visitor might change it to "Arnold" and the filter should update to that. Make sense?
The value of the select dropdown gets sent to my xano api as a url param. I need xano to filter my members by that input, but return only those with a true value. -
In that case, you want to use External Filtering (https://docs.xano.com/working-with-data/functions/database-requests/query-all-records/external-query-manipulation/external-filtering)
This allows you to make your filtering options completely dynamic from the front-end. -
Cool. Thanks very much Michael. That should get me there.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback