I have table on Dynamic page. I want data to be filtered based on logged in User’s email id. I have dome following code: I have tried both ‘#dataset1’ as well as ‘#dynamicDataset’ but it doesn’t work. I am getting all the records in table
@piushkg Looking at the code more closely, I’m not seeing where you are declaring the variable count before you use it in the console.log. That would result in a reference error that would halt the execution of the filtering code that comes after it.
So you know, it’s forum policy to put code in a code snippet block. It will allow for the easy copying and pasting by someone responding to your post.
It may just be my eyes, but I don’t see where you handle the Promise returned by the call to setFilter() of the dynamicDataset. So, the call to getTotalCount() will be wrong. And as @anthonyb mentioned, make sure that the variablecountis declared somewhere.
I also think you’re not retrieving the user’s email correctly.
You should do something like this:
$w.onReady(function () {
$w("#dynamicDataset").onReady(() => {
let currentUser = wixUsers.currentUser;
currentUser.getEmail()
.then((email) => {
userEmail = email;
console.log(userEmail);
console.log(' OR before count' + count);
$w("#dynamicDataset").setFilter(wixData.filter()
.eq("email", userEmail))
.then(() => {
console.log("Dataset is now filtered");
count = $w("#dynamicDataset").getTotalCount();
console.log(' OR after count' + count);
})
.catch((err) => {
console.log('in error' + err);
});
})
})
})
Note: I haven’t tested this. And I’m not sure if all of the brackets and parentheses are balanced (my eyes are crossing). I hope this helps.
Note2: Please note how I posted my code, nicely formatted, in a code block.