I have Collections that use an ID for filtering. For example, I want to get all tasks associated with a specific list by its ID.
I’m finding that I have to create a Page Variable to set the List ID and then bind the collection to use that Page Variable in order to filter tasks.
This doesn’t seem to be a good solution, especially if I have to use that Collection on another page, or if I’m displaying multiple lists on the same page.
Is there a way to simply pass the List ID as a parameter into the Collection call?
Apologies for the late reply. I’m a little bit confused by your question. I think what you’re looking to do is option 2 in this video but I’m not sure I understood your request correctly.
Could you share some screenshots or a short video explaining what you’re trying to do step by step?
Yes, you will need to create a variable to bind to your collection and dynamically filter the list/collection. Depending on your requirements, here are a couple of approaches you can consider:
If you need to display the collection list multiple times on the same page or different pages but only filter one list:
Filter each collection list individually by applying filters directly to each list.
If not:
Pass the ID as a parameter if your fetch call is set up to accept parameters.
Or add a filter to the collection within the fetch request itself.
No worries. It’s been awhile so I can’t remember exactly where this use came up, but here’s a video that sorta explains it.
Also, @Miguel, thanks for the help. I’m kind of following you, but I don’t quite understand what you mean by passing a parameter. I might need you to point it out with some screenshots. Are you referring to page parameters?
I don’t really want to use collections and then filter after the fact, especially if I just need one record from the database.
Update the variable every time I use the Collection with a workflow
Then, finally, call the Collection
Do I have that right?
I was hoping for a way where there isn’t the Steps 1 and 2.
With Step 1: I was hoping to setup a Collection in such a way where when I call the collection, I can pass a value instead of using a variable.
The challenge with using a Data → Variable is that, again, I have to remember what variable is being used by the collection in order to update it. With Data → Variables being the only thing we can use to store some sort of state throughout the app, the list of variables can get quite big.
So again, it relies on us to come up with some of structure or naming convention to make it easier to find the things we’re looking for.
Also, related to this, if a Collection is bound to a Data → Variable, one needs to be careful to not use that same variable with another collection. This is where having a dynamic input for Collection parameters would be a more user-friendly experience.
So it seems like a rule is forming:
One Data → Variable per Collection
Do not use the same Data → Variable for multiple collections
Thanks for the video, I see what you’re trying to do.
From my experience I don’t think there is a way to dynamically pass an ID when calling the collection without having some type a variable or input bind to it.
Since you don’t want to get a collection and then filter after the fact…
What I have done in my projects, is duplicate the same GET fetch so I can use it on multiple section of the page and pass a different ID to them, you will still need to bind it to an input or variable
I use a component that holds the logic for a list. For example, I have a file browser, that uses parameters to fetch the files in this (Project or folder). Instead of using collection to hold this I am actually calling it a single time in the workflow and storing the data inside the component.
When the component loads, it takes in ie. project_id and calls the function to get the correct data.
I use Supabase, so for me it is SELECT (with filter: project_id = X, for example) and then i return all rows, and store them in a component variable.
This variable is used to display the list.
This way, its really easy to seperate the variables since its inside the component.
This way you can also have several of the same components on the same page, and each component just calls whatever filter you need it to.
This does sound very similar. I also think I’ve tried it before, but it isn’t really an optimal solution, especially when dealing with data that ought to be protected based on user permissions.
Because it retrieves all the records:
the payload size is larger than it needs to be, especially if you just need one record.
a user can have access to all the records (you can watch the requests and see all the data coming through).
Here, I thought all along, I had to use Collections to do these types of dynamic queries. I was racking my brain trying to figure out why WeWeb would do this to us! Haha.