Hey! appreciate any help:)
I have a table “students” and 2 different fields: “student_grade” and “student_subject”.
I want to find students based on 2 different filters like “9 grade” and “math”.
When I press 2 different buttons it will show me the students that are in 9 grade and in math, does anyone know how to do it?
https://support.wix.com/en/article/about-connecting-multiple-database-collections
Or in code:
Note that this code will find everything in both fields and display it in just the one table.
import wixData from 'wix-data'
$w.onReady(function () {
$w('#searchButton').onClick(function () {
wixData.query("DatasetName")
.contains("fieldkey", $w("#searchInput1").value)
.or(wixData.query("DatasetName")
.contains("fieldkey", $w("#searchInput2").value))
.find()
.then((results) => {
let resultsItems = results.items;
console.log(resultsItems);
$w('#resultsTable').rows = resultsItems;
})
})
})
Or for search using two different buttons:
import wixData from 'wix-data';
$w.onReady(function () {
//TODO: import wixData from 'wix-data';
});
export function searchButton_onClick(event) {
wixData.query('DatasetName')
.contains('fieldkey', $w('#searchInput1').value)
.find()
.then(res => {
$w('#resultsTable').rows = res.items;
});
}
export function searchButton1_onClick(event) {
wixData.query('DatasetName')
.contains('fieldkey', $w('#searchInput2').value)
.find()
.then(res => {
$w('#resultsTable').rows = res.items;
});
}
Have a read of the Wix Data Query API here, so that you can possibly use another option instead of ‘.contains’:
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html