I have the below code and I don’t understand the results I’m getting. There are two issues: I get one count using setInterval (correct count), another count if using dataset onReady, and no count using setInterval if I hit the browser refresh button. I created code to getTotalCount of a dataset and display counts in a text in the header just to see the counts. See below:
import wixUsers from 'wix-users';
import { session } from 'wix-storage-frontend';
import wixData from 'wix-data';
let user = wixUsers.currentUser;
$w.onReady(function () {
// update header text based on interval
setInterval(function () {
$w('#textGroupSelectedName').text = session.getItem("groupAdminName");
$w('#textCustomerCount1').text = $w("#dataset13").getTotalCount().toString();
// above line initiallhy results in 2 which the the correct filtered count
// however, if I hit the browser refresh button the resulting count is 0
}, 1000);
// when header user full dataset is ready (user login email text is updated)
$w("#dataset21").onReady(() => { // this is the user full dataset to get loged in email
// header text
$w('#textGroupEmail').text = session.getItem("groupEmail"); // get login email
// $w('#textGroupEmail').text is connected to user full dataset in header
// set customer profile dataset filter
let userEmail = $w('#textHeaderEmail').text;
// save user login email to session variable
session.setItem("groupEmail", userEmail);
// filter dataset based on matching email
$w("#dataset13").setFilter(wixData.filter()
.eq('customerEmail', userEmail)
);
// show repeater and update header dataset count
$w("#dataset13").onReady(() => {
$w('#listRepeater').show();
$w('#textCustomerCount2').text = $w("#dataset13").getTotalCount().toString();
// above line results in 5 which is total dataset population not the filtered count
});
});
});
Site is in development but is published. I’m using Wix Editor in desktop mode and the purpose is to store the signon user email in a session variable in order to use the stored value as a parameter in queries thoughout the site. My browser is Brave (Chromium based) and I’m running on Linux Manjaro.
Please help!