Does anybody know whether it is possible to use Velo code to reassign a dataset to a different collection after a button is clicked?
Thanks
Conal
You can simply add multiple datasets to the same site. And populate the data from each based on certain conditions (e.g. populate the repeater from one dataset on load and the change repeater’s data when a button is clicked populate same repeater with data from a different dataset).
Or maybe you can provide more context on what you are trying to achieve switching the datasets?
Thank you for your reply. I am developing an educational resource. Each data collection contains a set of words and definitions relating to a science topic. The user will choose the topic required by clicking on a button and then a table of words relating to that topic will display on the screen.
The issue I have is there are a lot of topics to choose from and I am having to put about 30 datasets on one page. If this is the best method I am happy to stick with it. However, I thought it might be more efficient just to have one dataset on the page, but link it to the relevant collection after the user has made their choice.
Many thanks for your help.
Conal
As the data is located in different collections, the best option here will be not using datasets at all. The approximate scenario you can use would be:
-
Add a dropdown with topics (any labels, but values should be equal to corresponding collection IDs).
-
Add a repeater to display data.
-
Add the onChange event handler to the dropdown.
-
Based on the value (topic) the customer changed to, query() the relevant collection (the collection name would be passed from the dropdown event.target.value) for the items.
-
Then populate the gotten items to the repeater data .
You can learn more about working with Wix Data API in the article .
Thank you. I will give that a try!