Having trouble using the Adding Collection Data Search Functionality
Modified as follows but it does not populate any data into the results table
What am I doing wrong?
import wixData from “wix-data” ;
export function RegionFinder_click ( event ) {
// Runs a query on the "School Districts collection
wixData . query ( “School Districts” )
// Query the collection for any items whose “Name” field contains
// the value the user entered in the input element
. contains ( “schoolDistrict” , $w ( “#searchBox” ). value )
. find () // Run the query
. then ( res => {
// Set the table data to be the results of the query
$w ( “#resultsTable” ). rows = res . items ;
});
$w . onReady ( function () {
$w ( “#resultsTable” ). columns = [
{
“id” : “schoolDistrict” ,
“dataPath” : “schoolDistrict” ,
“label” : “School District” ,
“type” : “string” ,
}, {
“id” : “region” ,
“dataPath” : “region” ,
“label” : “Region” ,
“type” : “number” ,
}, {
“id” : “regionalDirector” ,
“dataPath” : “regionalDirector” ,
“label” : “Regional Director” ,
“type” : “string” ,
}];
});
}
What am I doing wrong?
What you are doing wrong is → You do not use a good formated CODE-STRUCTURE.
If you would do it, you would see all the errors inside your code emmidiately.
import wixData from "wix-data";
$w.onReady(()=>{
$w('#myButtonIDhere').onClick(()=>{
setupTable();
RegionFinder();
});
});
function setupTable() {
$w("#resultsTable").columns = [
{
"id": "schoolDistrict",
"dataPath": "schoolDistrict",
"label": "School District",
"type": "string",
},
{
"id": "region",
"dataPath": "region",
"label": "Region",
"type": "number",
},
{
"id": "regionalDirector",
"dataPath": "regionalDirector",
"label": "Regional Director",
"type": "string",
}
];
}
function RegionFinder() {
wixData.query("School Districts")
.contains("schoolDistrict", $w("#searchBox").value)
.find()
.then(res => { console.log(res)
$w("#resultsTable").rows = res.items;
});
}
What exactly did not work ?
Which ERROR do you get in CONSOLE ?
Just to say → it did not work → helps either YOU, nor ME.
What do you get in your console? Can you see any RESULTS of the query?
Did you checked and replaced all element-IDs with your own ?
@russian-dima I apologize - I had a typo.
Now works - many thanks!