@jonatandor35 very helpful thanks. A follow up question hope you have a bit time to help. my draft website is at https://stephenxj5.wixsite.com/yyeducation/copy-of-school-search
It’s designed to contain 2 steps.
- Step 1 in the current school section which is linked to collection"Chin_School": choose the province then the school, the “vlookup” function you helped me earlier will pick up a value from the table - requiredValue = matchRow.cat
- Step 2 in the target school section which is linked to dataset “dataset1”: apart from the visible filtering “Gender”, “Town”, “Postcode” as you can see, there is an additional hidden filtering - “Cat” equals to requiredValue from step1.
2 Questions:
- the section where the requiredValue is retrieved in step1 might not be correct
- when I refer to requiredValue in step2, it says “requiredValue is not defined”.
Please see the codes attached below.
import wixData from ‘wix-data’;
$w.onReady( function () {
uniqueDropDown1();
});
function uniqueDropDown1 (){
wixData.query("Chin_Schools")
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w("#province").options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.province);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}
export function province_change(event,$w) {
uniqueDropDown2();
$w(“#schooldrop”).enable();
}
function uniqueDropDown2 (){
wixData.query("Chin_Schools")
.contains("province", $w("#province").value)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w("#schooldrop").options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.schoolName);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}
export function schooldrop_change(event,$w){
const matchRow = $w(“#Chin_Schools”).rows.find( e => e.firstName === $w(“#schooldrop”).value );
const requiredValue = matchRow.cat;
}
export function SearchButton_click(event) {
let searchGender = $w(“#GenderSelect”).value;
let searchTown = $w(“#Town”).value;
let searchPostcode = $w(“#Postcode”).value;
let searchcat = 1;
$w(“#dataset1”).setFilter(wixData.filter()
.contains(“gend1618”, searchGender)
.contains(“town”, searchTown)
.contains(“pcode”, searchPostcode)
.eq(“top3SubjectRankGroup”, searchcat)
);
}