How to query database with a search button?


I am wondering how can I do a search on a collection with a button press?
My goal is to allow the user to input a specific number in the VIN Number field and upon clicking the search button, it queries the specific collection for it. If there is a hit, a hidden text will appear at the bottom with further information on continuing.

The dropdown list is sort of a gimmick. It allows user to select which model they are looking for and then key in the VIN Number even though the VIN Number is unique to the model itself.

Any help is very much appreciated. I am struggling with this…:relieved:

import wixData from “wix-data” ;

$w . onReady ( function () {

$w ( “#recalltable” ). columns = [
{
“id” : “col1” ,
“dataPath” : “title” ,
“label” : “VIN Number” ,
“width” : 120 ,
“type” : “string” ,
},
{
“id” : “col2” ,
“dataPath” : “model” ,
“label” : “Model” ,
“width” : 100 ,
“type” : “string” ,
},
{
“id” : “col3” ,
“dataPath” : “code” ,
“label” : “Campaign Code” ,
“width” : 50 ,
“type” : “string” ,
}];

});

export function searchbtn_click ( event ) {

wixData . query ( “Recall” )

. eq ( “title” , $w ( “#vininput” ). value )
. find ()
. then ( res => {
$w ( “#recalltable” ). rows = res . items ;
$w ( “#recalltable” ). expand ();
});
}

I have found the solution to the query problem I had and it works like a charm! (Code is as of above) But how do I then display a text after the search to notify whether it was successful or not?

As you already mentioned by yourself…

But how do I then display a text after the search to notify whether it was successful or not?

So, in the → then(()… -code-part, you will have to find out wether ITEMS were found or not!

.then(res=>{
    $w("#recalltable").rows=res.items;
    $w("#recalltable").expand();
});

How to do that?
Maybe if ITEMS were found → the length of the found items will be bigger then —> 0 ???

.then(res=>{
    if (res.items.length > 0) {
        console.log("Items found!);
        $w("#recalltable").rows=res.items;   
    }    
    else {
        console.log("No ITEMS found!);
        $w("#recalltable").collapse();
    }
});