Hi guys,
I'm building a website that allows people to read and write reviews. I've been able to setup the search page to search for a single element (Full name), but i'm having trouble getting it to filter the results of the search. I'd like to filter the results by country and DOB. I've tried a few different approaches that have been recommended in various posts on this site, but always end up getting a truckload of errors and causing more problems. I'll post the page code for the single attribute search below. Any help you can provide me would be greatly appreciated!
Kind regards,
Leigh
Â
Â
import wixData from "wix-data"; // For full API documentation, including code examples, visit http://wix.to/94BuAAs //TODO: write your page related code here...
export function searchbutton_click(event) { //Add your code for this event here: // Runs a query on the "recipes" collection wixData.query("Tenant_Blacklist") // Query the collection for any items whose "Name" field contains // the value the user entered in the input element .contains("tenantFullName", $w("#input7").value) .find() // Run the query .then(res => { // Set the table data to be the results of the query $w("#table1").rows = res.items; }); } $w.onReady(function () { $w("#table1").columns = [ { "id": "col1", // ID of the column for code purposes // The field key in the collection whose data this column displays "dataPath": "tenantFullName", "label": "tenantFullName", // The column header "width": 100, // Column width "type": "string", // Data type for the column // Path for the column if it contains a link "linkPath": "link-field-or-property" }, { "id": "col2", "dataPath": "photos", "label": "photos", "visible": true, "type": "image", "linkPath": "link-field-or-property" }, { "id": "col3", // ID of the column for code purposes // The field key in the collection whose data this column displays "dataPath": "scoreOutOf10", "label": "scoreOutOf10", // The column header "width": 100, // Column width "type": "string", // Data type for the column // Path for the column if it contains a link "linkPath": "link-field-or-property"
},
]
You are using this tutorial, please follow it carefully and make sure that your onReady function is after your import calls and the export functions are after the onReady function code.
https://support.wix.com/en/article/corvid-tutorial-adding-collection-data-search-functionality
Â
See here for onReady info.
https://www.wix.com/corvid/reference/$w.html#onReady
Hi givemeawhisky,
Yes, that is the tutorial that i used to create a search function for a single attribute (ie full name). That part works fine.
What i'm trying to do is filter the data that comes as a result of that search with 2 additional attributes (date of birth, and country), and output only the filtered data to the table. Are you able to point me in the direction of where i can find the correct tutorial for that?
Can anyone provide me with a useful answer?
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html
Â
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#or
Hi Leigh,
Not sure what is the exact functionality you are trying to implement. Does the 'Tenant_Blacklist' collection has 'country' and 'DOB' fields? If this is the case, maybe you could add two input fields to your page (for DOB and country) and modify the code to something like this:
Â
export function searchbutton_click(event) {
wixData.query("Tenant_Blacklist")
.contains("tenantFullName", $w("#input7").value)
.contains("tenantCountry", $w("#input8").value)
.contains("tenantDOB", $w("#input9").value)
.find()
.then(res => {$w("#table1").rows = res.items; });
}