Working in Preview, not in Live (getTotalCount())

Hi,

This is the code:

export function table1_dataChange(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("#dataset1").onReady( () => {
 let count = $w("#dataset1").getTotalCount(); 
    $w("#text10").text = String(count);
   } );
 }

This one counts the filtered results of my dataset and sends the value to a text box. It only works in Preview mode, not in Live.

Any ideas why???

Thanks.

Check the collection permission.
Check the live data.

Hi,

Collection permissions are all set to: anyone.
Live data are synced to sandbox ones so I guess they’re the same with Preview.

Still no luck.

Try the following code:

$w.onReady(() => {
 $w("#dataset1").onReady( () => {
  $w("#table1").onDataChange(event => {
   let count = $w("#dataset1").getTotalCount(); 
   $w("#text10").text = String(count);
  })
 })
})

@jonatandor35 Thanks but this didn’t do the trick either. Still ok with Preview but no luck inLive.

Here’s the live page (the counter is centered at the bottom of the table, “query returned xxx results”. It should start with the number 450 and then fluctuate based on your choices on the three white dropdowns (year, category, language).
https://gemats.wixsite.com/gkmatsaridis/copy-of-law-database-1

You are using the datlaset onReady() incorrectly. It is only to be used when you need to use the dataset as soon as it is ready. Once it is ready, you can no longer use the dataset onReady() event handler as the event already occurred and won’t occur again . The code in table1_dataChange() will never run, since all it is doing is setting the code to run when the dataset is ready. Since the dataset is already ready, the code does not get executed.

Your code should look like this:

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

I’m not saying that this will fix the problem, as you might have other issues in your code. But at least the code should run if the table1_dataChange() event handler is triggered.

Thanks for the explanation. Indeed, as you guessed, your updated code did not fix the problem, suggesting that there are othe “issues in my code”. But again, what issues, other those discussed above, may prevent proper Live display, when the Preview runs perfect?

I just checked and I believe that this issue is related to a rollout of a system release for site performance improvements.

Give me a few moments and I hope to set things up for you. Don’t touch that dial.

In any case, the onReady() was a problem and it’s good that you fixed it.

Hey George…

It should be good now. Count to 100 and try again. You might need to count to 200 or so, but you should see it working shortly.

98, 99, 100… reload, done! Thank you sir!! :slight_smile:

Sir? Wow! Most people just call me “hey you!” … or worse.