Simple DB query

I am trying to create a very simple test query, but I am having issues getting it going. When I preview, I don’t get any results.

Here is my DB

Here the editor

Here is the code just in case:
import wixData from ‘wix-data’;

$w.onReady(() => {
$w(“#dataset666”).setFilter( wixData.filter()
.contains(“Title”, “of”)
);
});

Here is the results page:


When I take all my code out, here is the results page:

Doesn’t $w(“#dataset666”) contain the data that is used by my table which is connected to #dataset666?

Thanks!

To learn more about creating searches and filters via code, see:

Definitely, spend some time with the reference links Yevheniia lists above.

Regarding your specific question, I’m noticing a couple things.

You need to issue an onReady for the dataset itself like the following to ensure that it is fully loaded before doing anything with it:

$w.onReady(() => {
  $w("#dataset666").onReady(() => {   
    $w("#dataset666").setFilter( wixData.filter()         
      .contains("title", "of")     
    ); 
  }); 
 }); 

Also, notice that “title” should be in lower case. You use the field key from the “Manage Field” dialog in the database area.

1 Like

anthonyb, thank you! ARRGH, the field key not the field name. I wonder why setFilter doesn’t kick back an error code because there is no field called “Title,” only “title.” Maybe I need to learn how to use try and catch? Maybe dying silently is a good thing? I will read up a little more on setFilter and wix-data to see if I am missing some error catching opportunities.

If I may bother you for one more clarification…
I read this: Wix Editor Elements ($w) - Velo API Reference - Wix.com
“Use the onReady() function for code you want to run before the user starts interacting with your page… The onReady() event handler may be called twice during the page rendering process, once server-side and once client-side.”

While the example works just fine, is this not calling onReady twice on the client side? Or you can call onReady generally and you can call onReady within the context of a page element/database connection too?

$w.onReady(() => { // Prepare the page before the user starts using the page.
$w(" #dataset666 #dataset666 “).onReady(() => { // Connect to DB so I can display some data
$w(” #dataset666 ").setFilter( wixData.filter() // Get some data based on filter
.contains(“title”, “of”)
);
});
});

Finally, what is a site tab vs page tab? Is that a Wix thing or an HTML thing?