Dear All, hope everybody is safe.
Please not that I am not a coder, but an avid learner. I am adding some search functionalities to my website. I used the CORVID tutorial to add the search function connected to a database with user input and displaying the results in a table. That worked great, amazing tutorial.
Now I want to step it up and instead of having a table I would like to have a repeater that display the results with all the additional info gathered from the database. I tried by myself adapting some code of other posts but the search doesn't happen. Any help or redirection to pertinent posts would be amazing!!
Database: Reviews
Repeater: repeater1
Input box: input1
search button: button1
field key for search: title1
The first option that I used was:
import wixData from "wix-data";
let repeater_results = '';
export function button1_click(event) {
//Add your code for this event here:
wixData.query("Reviews")
// Query the collection for any items whose "Name" field contains
// the value the user entered in the input element
.contains("title1", $w("#input1").value)
.find() // Run the query
.then(results => {
let firstItem = results.items[0]
repeater_results = firstItem._id;
wixData.query('Reviews')
.contains("title1", $w("#input1").value)
.find()
.then(results => {$w("#repeater1").data = results.items }
The second option that I used was:
import wixData from "wix-data"; export function button1_click(event) { //Add your code for this event here: wixData.query("Reviews") .contains("title1", $w("#input1").value) .find() // Run the query .then(res => { // Set the table data to be the results of the query $w("#repeater1").data = res.items; $w("#repeater1").expand(); })
Thank you so much for your help!
Marco
Hello,
Take a look at the examples below:
Example: Search a Database
Example: Mega Search
Example: Checkbox Dropdown filter
APIs you can refer to:
https://www.wix.com/corvid/reference/wix-dataset.html
https://www.wix.com/corvid/reference/wix-data.html
https://www.wix.com/corvid/reference/$w.Repeater.html
Some related forum posts:
https://www.wix.com/corvid/forum/community-discussion/search-function-for-a-repeater
https://www.wix.com/corvid/forum/community-discussion/equal-to-or-more-than