Hi team,
Aim: I am looking for some help adding search and filter options to the resources page of my website exactly like the one in this Wix video.
Context:
I would like to set up a page that hosts all our organisations resources from which visitors to our site can search for a resource (eg; annual report) or filter results (eg report, submission etc). I have watched this video and read implemented code from this article that Wix recommends. I have also attempted to use the code from this forum post. I have also found Code Queen’s videos really helpful ( ‘Add search function to Wix Form’ and ‘Conditional Filtering Dropdowns’ ).
However as a newbie to coding I haven’t had any success as of yet so thought I would reach out for some help.
Where I am up to:
I have successfully added in a repeater and linked this to a data set called ‘Resources’. When I click on a resource the document opens up. Everything is all working in the repeater as it should. Happy with this.
The problems come when I try to get search results or the options in the filter to show in the repeater using code. I have tried following all the resources above to write the code. The code below is based off this article and is the code I currently have on my resources page. I am beginning to think as I am using a repeater and not a table this might be the problem? I understand that the red dots indicate errors in my current code.
Current Code (See image attached):
import wixData from “wix-data”;
export function searchButton_click(event) {
// Runs a query on the “resources” collection
wixData.query(“Resources”)
// Query the collection for any items whose “Name” field contains
// the value the user entered in the input element
.contains(“title”, $w(“#search).value)
.find() // Run the query
.then(res => {
// Set the table data to be the results of the query
$w(”#repeater1").rows = res.items;
});
}
$w.onReady( function () {
$w(“#resultsTable”).columns = [{
“id”: “col1”,
“dataPath”: “title”,
“label”: “title”,
“type”: “string”,
}, {
“id”: “col2”,
“dataPath”: “ResourceType”,
“label”: “ResourceType”,
“type”: “string”,
}, {
“id”: “col3”,
“dataPath”: “Description”,
“label”: “Description”,
“type”: “string”,
}];
});
export function resource_change(event) {
// Runs a query on the “Resources” collection
wixData.query(“Resources”)
// Query the collection for any items whose “Name” field contains
// the value the user selected in the dropdown
.contains(“ResourceType”, $w(“#resource”).value)
.find() // Run the query
.then(res => {
// Set the table data to be the results of the query
$w(“#repeater1”).rows = res.items;
});
}
Details:
Search input type: #search
Filter input type: #resources
Repeater type: #repeater1
Image screenshots attached of:
-Database:Resources
-Current editor page
-Current preview page
-Current code
I have been working on this for a few days now so would very much appreciate some advice.
Thank you!
Kind regards,
Maddie