Hello,
I am hoping somebody can help me.
I have a dataset and I have dynamic pages connected to this data set
In the list page I have a repeater and I have managed to add a search bar for the repeater.
Within the container in the repeater I have certain fields I show and then a ‘click for more’ button which takes them to the list page.
My query is, within the dataset I have a field called ‘Policy Type’ there are 2 options in this, lets call them ‘true’ and ‘false’.
I want to have 2 different pages which show ‘true’ and a specific layout and ‘false’ and a specific layout.
As you can see from the way i am describing it I do not know how best to search this so cannot find my answer.
Any help would be gladly appreciated.
Thanks
Hey @Harriet_Morton-Liddl!
This definitely sounds doable. You can build 2 different item pages, one for the “true” and one for the “false”. Each of those item pages can have their own layout and data “pulled” from the database.
As for the buttons, I think you’ll need a small amount of conditional logic here. An “if this, then this, else do this” sort of setup.
@thomasj do you have a snippet or something for this one?
1 Like
If the dataset is connected to a dynamic page, you can use a property to conditionally render different Wix Elements. This should allow you to change the layout based on the whether the current item page has the property true or false within the dataset.
To accomplish this you can use getCurrentItem() from the Wix Dataset API.
Here’s a example of what it would look like:
$w.onReady(() => {
$w("#myDataset").onReady(() => {
const currentPageObj = $w("#myDataset").getCurrentItem();
if (currentPageObj.policy === "True") {
//Handle Showing Wix Elements to create layout for dataset items with the "True" property
} else {
//Handle Showing Wix Elements to create layout for dataset items with the "False" property
}
});
});
Thanks so much for your help.
I am fairly new to coding so could do with some additional support… I have this logic on my page already… where would the above fit in?
import wixData from ‘wix-data’;
$w(‘#resetButton’).hide();
$w.onReady(function () {
});
export function searchButton_click(event) {
search();
// This function was added from the Properties & Events panel. To learn more, visit Working with the Properties & Events Panel
// Add your code for this event here:
}
function search() {
wixData.query("Policy")
.contains("companyName", String($w("#searchqueryinput").value))
.or(wixData.query("Policy").contains("companyWebsite", String ($w('#searchqueryinput').value)))
.find()
.then(results => {
$w('#listRepeater').data = results.items});
$w('#resetButton').show();
$w('#resetButton').enable();
$w('#searchButton').hide();
}
/**
- Adds an event handler that runs when the element is clicked.
Read more
- @param {$w.MouseEvent} event
*/
export function resetButton_click(event) {
$w(‘#dynamicDataset’).setFilter(wixData.filter());
$w(‘#searchqueryinput’).value = undefined;
$w(‘#searchButton’).show();
$w(‘#searchButton’).enable();
$w(‘#resetButton’).hide();
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
}