(SOLVED) - What am I missing? (syntax problem?)

@gemats

Also, console.log (count) returns NULL… ???

Ok, this is a little bit strange.
I would first check the following things…

  1. Check my DATABASE —> are the same items in my LIVE-Database as in Previewmode? (Databases are synced?)
    Because if not, perhaps you look at the preview-database, which can have 446-items, but your live database is empty. Or vise versa.

  2. Check also the database-permissions, perhaps they block your code.

  3. Check Read & Write options (already mentioned by J.D.).

  4. Delete all other code, like J.D. said before and just do a simple test with related code-part.

  5. Perhaps take a look again at my example, which works without any errors again and try to reconstruct exactly the same situation.

  6. Also check the right options and connection of your dataset.

And if nothing helps, than i would do the next step and post it into “rolling out improvements”.

@russian-dima all options above checked and normal, as expected. Also, running your latest code I get this:
An error occurred in one of datasetReady callbacks TypeError: Cannot read property ‘toString’ of null

And againl: why would the let count = $w( “#dataset1” ).getTotalCount(); work inside the export function and not in the on.Ready()??

export function table1_dataChange(event) {
 let count = $w("#dataset1").getTotalCount(); 
        console.log(count) <-- THIS ONE GIVES ME 445, ALL GOOD.
        $w("#counter").text = String(count);
}

But this one, returns NULL:

$w.onReady (function() {
    $w("#dataset1").onReady(() => {
 let count = $w("#dataset1").getTotalCount(); 
        console.log(count)<-- NULL

Can you make a pic of your database? Live and preview (just first 3-5 rows of data and the HEADER).

Can you show a pic of your dataset-options?

And your last used code (full code which is actually used for the simple example to solve the problem).

EDIT: already tried to run your code in another BROWSER ? Internet-Explorer / Edge / FireFox / Opera / Brave or something like that ?

Ok.

  1. Pics of the database (there are referenced fields in here):

  1. Dataset options:

  1. Full code on the page :

export function table1_dataChange(event) {
 let count = $w("#dataset1").getTotalCount(); 
        console.log(count)
        $w("#counter").text = String(count);
}

$w.onReady (function() {
    $w("#dataset1").onReady(() => {
 let count = $w("#dataset1").getTotalCount(); 
        console.log(count)
        $w("#counter").text = count.toString()
 
 if ($w("#counter").text === "29") { 
                $w("#text29").show();
        }
 else {
        $w("#text26").show();
        }
    })
});



export function hoverZone_mouseIn(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverEfarmostiki').show();
    $w('#checkbox2').hide();
    $w('#vectorImage3').hide();
    $w('#hoverBox').show();
}

export function hoverZone_mouseOut(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverEfarmostiki').hide("fade");
    $w('#checkbox2').show("fade");
    $w('#vectorImage3').show("fade");
    $w('#hoverBox').hide("fade");

}

export function hoverzoneEfarm1_mouseIn_1(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverYpoyrgeio').show();
    $w('#hoverboxYpoyrgeio').show();
    $w('#hoverzoneEfarm').hide();
}

export function hoverzoneEfarm1_mouseOut(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverYpoyrgeio').hide("fade");
    $w('#hoverboxYpoyrgeio').hide("fade");
    $w('#hoverzoneEfarm').show("fade");
}

export function hoverzoneIsxyon_mouseIn_1(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverboxIsxyon').show();
    $w('#hovermainIsxyon').show();
    $w('#vectorImage2').hide();
    $w('#checkbox1').hide();
}

export function hoverzoneIsxyon_mouseOut_1(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverboxIsxyon').hide("fade");
    $w('#hovermainIsxyon').hide("fade");
    $w('#vectorImage2').show("fade");
    $w('#checkbox1').show("fade");
}



@gemats

Ok, let’s do it together!

  1. When you get this part to work, then you will get all other code-parts to work.
$w.onReady (function() {
    $w("#dataset1").onReady(() => {
      let count = $w("#dataset1").getTotalCount(); 
       console.log(count)
    })
});
  1. I would suggest you to create a second dataset (“dataset2”) and connect it with your Database (“LawDatabase”). It can be setted-up to “Read-Only”.

  2. Did you set the Database-permissions to “everyone” ?

  3. Run the given code (you have just to open the site) and look what does the console say?

If you get already an error or you have “null-result”, try to make a more simple DATABASE with just the given “title” field and put 3-10 items into it.

  1. Connect your dataset, with this new DATA-COLLECTION, run the code again.
    Did something changed, or still no results?

EDIT: DEACTIVATE all your OLD-CODE before you do the test.
You can do it when you comment out your code like this…

Start to comment out CODE ----> /*

all CODE here will be commented out and gets deactivated.

End to comment-out CODE —> */

@russian-dima Ok, the code above works in another test dataset. It returns to console the correct number of items in the dataset. But in my main dataset, it returns null . All permissions are set to anyone.

@gemats

So now you have the first answer. Something is wrong setted up with your other dataset, or even with your whole data-collection.

You use HEBREW, perhaps there are some conflict with this?
Check your Data-Collection and your “dataset1”.

I don’t think you have to put this into “rolling out improvements” thread.

@russian-dima actually it’s Greek. I won’t even enter an investigation whether unicode affects JS execution (???). I’d rather quit the whole project. Thanks for everything, the last 3 days!

@gemats

Ohh sorry, i thought it was hebrew :grin:.
No! Why you want to give up now?
You are on the right way.

Keep trying! Never give-up! There are always ways to success! :wink:

@russian-dima Okay. I fixed it. And I didn’t fix it.

a) I fixed it.
Dataset 1 is connected to Dataset 2 via a referenced field which I use as a Filter.


If I delete this filter, the code works. Again, to remind you, the filter above does not do any bad to this:

export function table1_dataChange(event) {
 let count = $w("#dataset1").getTotalCount(); 
        console.log(count)
        $w("#counter").text = String(count);
}

This works with or without the Dataset filter. It only affects this:

$w.onReady (function() {
    $w("#dataset1").onReady(() => {
 let count = $w("#dataset1").getTotalCount(); 
        console.log(count)
        $w("#counter").text = count.toString()
 
 if ($w("#counter").text === "29") { 
                $w("#text29").show();
        }
 else {
        $w("#text26").show();
        }
    })
});
  1. I didn’t fix it.
    But if I delete this filter, my dropdown menu stops working… How can I include both my datasets in the on.Ready()? I mean, what would be the syntax?

To complete this thread, I’d like to report that I solved my problems, most probably in a quite unorthodox way.

Since the export function to get me all items counted in my dataset1 was working, I thought just to try to embed my conditionals just below it and do not mess with the on.Ready(), due to problems found with the connection between my 2 datasets.

So I ended up with this:

export function table1_dataChange(event) {
 let count = $w("#dataset1").getTotalCount(); 
        console.log(count)
        $w("#counter").text = String(count);
 if ($w("#counter").text === "1") {
            $w("#text25").show();
            $w("#text12").hide();
 
        } else {$w("#text12").show();
                $w("#text25").hide();
 
        }
}

Smart or dumb, I don’t know, but it finally works. Thanks J.D. and russian-dima for your efforts.

@gemats

I don’t understand why a filter should change or affect onto the code.

Just right from the beginning.

  1. You have a DATABASE where you have some items in it.
  2. This DATABASE is connected with a DATASET. (let us say all settings are ok).
  3. Now the action which you want to achieve, let us say the following…

a) You want to count the items right from the beginning when page has loaded.
b) You want to show the result of this counter in a textfield (let us call it “TXTcounter” ).
c) You want to show up a Textfield when some special counting-numbers are given, let us say you have 448 -items in your DATABASE.

Now you start coding (after you have setted-up and connected your DATASET correctly).

  1. When page is ready…
$w.onReady (function() {




})
  1. When page is ready & dataset is also ready…
$w.onReady (function() {
    $w("#dataset1").onReady(() => {
        

    })
})
  1. When page & dataset is ready —> get the number of items in my data-collection…
    Of course, first we define a new variable (“count”) and then fill it with the counting result of the amount of database-items. And we also do not forget to make a little CONSOLE-LOG !
$w.onReady (function() {
    $w("#dataset1").onReady(() => {
        let count = $w("#dataset1").getTotalCount()
           console.log("My total items in DB = " + count)
    })
})
  1. Now we want to fill the Textfield —> “TXTcounter” with the founded counting result…

OKEYYYYYY, well done.

Then i stop here :grin:. I just wanted to show you the way, how i would try to solve the problem. But you got it already!

As i told you —> NEVER GIVE UP !:wink:

@russian-dima Thanks my friend. Just for the sake of it, the steps are these (copy-paste from you, above):

  1. You have a DATABASE where you have some items in it.
    as a matter of fact, I have 2 connected databases through a reference field.
  2. This DATABASE is connected with a DATASET. (let us say all settings are ok).
    for each DB collection I’ve set up a dataset on the page in order to be able to use dataset2 values to filter (dropdown) dataset1 values. I followed the tutorials for this.
  3. Now the action which you want to achieve, let us say the following…

To achieve this, I add a filter to Dataset1 based on the referenced field in Dataset2 (‘includes’ relationship). Dataset2 values are also values of a dropdown. So when I select a value from this dropdown, the whole Dataset1 is filtered based on this value (it’s the Actors and Movies tutorial, somewhere).

So, strangely enough, if I delete this filter, in other words, if I delete the connection between 2 datasets, your code and J.D. code was working fine (the on.Ready()) part. But if I do this, I just can’t filter my records any more .

So since the export function was already working to count the total number of items, I crossed my fingers and decided to put the if-else and .show - .hide just below it.

And it worked!!

@gemats

Just one more little info.

Of course you could set the filter also BY CODE.

https://www.wix.com/corvid/reference/wix-dataset/dataset/setfilter

But this would be a new chapter.

Good luck and happy coding! And thanks J.D. at this point for his lessons! I have learned a little bit, too.