I have a database collection and I have an option for user to filter the collection using a filter button and this code in the click event of the filter button : $w(“#datasetname”).setFilter(wixData.filter().eq(“parameter”, parameter_value));
But when I click on the filter button, the filtering option is working fine but other database properties like $w(“#dataset1”).getTotalCount(); is giving the total count of the database before filtering operation. And if i click on the filtering button again, $w(“#dataset1”).getTotalCount(); gives the correct value that corresponds to the number of elements after filtering operation.
That means the user need to click on the filter button 2 times to get the desired properties of my database . Is there any way to solve this issue so that as soon as the filter button is clicked, the database table is updated and the properties of the filtering operation are accessible? Thanks
I recommend refreshing the dataset after filtering the dataset and before using the getTotalCount function. Should the issue persists, please provide us with the site URL and the page name so we can have a look.
Hey Tal,
Thank you for your recommendation but adding refresh function is not working everytime.It’s working when the number of database elements after filtering is less and is not working if this number is high(in my case more than 7)
But I got a solution that is working from stack overflow using a delay:
Usage:
delay(function(){ // do stuff }, 600 ); // end delay
I guess my database is not getting enough time to update the database properties after the filtering operation. By using the above code, the filtering operation is working as expected. thanks for your support.
Hey guys,
I was having this same problem, but I found the proper solution that doesn’t need a delay. The trick is to use “then” after you filter. In this case:
$w("#datasetname").setFilter(wixData.filter().eq("parameter", parameter_value))
.then( () => {
// Do stuff with getTotalCount
});
Hope that helps anybody else having this issue in the future!
Thank You very much. 3 days I try to solve this Issue with Dable Running of GETTOTALCOUNT…
I’m a begginer in WIX but many many years ago at school in Russia I studiing programming and have some expearence. I see that WIX has Isue with assinchronical of running som statements and functions