is there anyway to filter the data before opening the dynamic page? I have a collection with several fields i would like to match. If there is 1 match, I want it to open a dynamic(product) page of that item. If there are more than 1, I would like it to open an (All) dynamic page with just that data.
I recommend setting up a loader on the dynamic page until the processing is done, then show the actual content after that.
You can determine whether you want to show the page item or redirect to another page.
To get the current page item, you need to wait for the page and the dataset to get ready, then run your query afterward.
$w.onReady(() => {
$w('#dataset').onReady(() => {
const item = $w('#dataset').getCurrentItem();
// Run your query here
wixData.query('collection').eq('fieldId', item.value).find().then((x) => {
if (x.length > 0) {
// There are more than one item, redirect the user to another page
wixLocation.to('<Your page URL>');
} else {
/* There's only matching item, hide the loader and show the page
content, or redirect to another page if wish */
}
})
})
})
Remember to import the wix-location module to be able to redirect the users.
Thank you for your reply! My biggest issues is comparing multiple fields. Can I use multiple “.eq” statements? and what is the best way to integrate a loader?
You can have a multi-state box with the default state being the initialization state with a gif or HTML loader, then change the state when the processing is done.