Dataset not filtering?

My code was working last year, but I just noticed that it stopped working now :frowning: Anything wrong with it?

FYI, my dataset has 2 columns:

  • Date - stored as text in DD/MM/YYYY
  • Text - which is liked to the textbox displayed in the site
import wixData from "wix-data";

var d = new Date();
var todayStr = d.getDate() + "/" + (d.getMonth()+1) + "/" + d.getFullYear();
console.log(todayStr);

$w.onReady(function () {

$w("#dataset1").setFilter(wixData.filter().contains("date", todayStr));
console.log($w("#dataset1"));

});

To make sure that the dataset is ready before you set the filter you need to use the dataset.onReady() function. You want something like this:

$w.onReady(function () {
    $w("#myDataset").onReady(() => {
        console.log("The dataset is ready");

        let d = new Date();
        let todayStr = d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear();
        console.log(todayStr);
        $w("#dataset1").setFilter(wixData.filter().contains("date", todayStr))
            .then(() => {
                console.log("Dataset is now filtered");
            })
            .catch((err) => {
                console.log(err);
            });
    });
});