Hi there, like the title says, I have a problem related to getting the total pages of the Dataset after applying a filter.
Example:
let newFilter = wixData.filter();
newFilter = newFilter.eq('sale', true);
$w("#dataset").setFilter(newFilter);
let pageNumber = $w("#dataset").getTotalPageCount();
This code is executed while applying the filter and returns 0 instead of the correct number.
If I want to get the correct number of pages I need to activate a second action like clicking a button and re-executing the function:
let pageNumber = $w("#dataset").getTotalPageCount();
I need to get the total filtered page count in the same action while applying the filter to refresh also the pages buttons.
How can I do that?
Thank you.
Keep in mind that the setFilter() function returns a Promise and you need to take care of that. You can do something like this:
$w("#dataset").setFilter(newFilter)
.then( () => {
console.log("Dataset is now filtered");
let pageNumber =$w("#dataset").getTotalPageCount();
} )
.catch( (err) => {
console.log(err);
} );
See the following for more information about Promises:
Hey there Yisrael, thank you for answering. I tought I deleted this thread since I found a different solution triggered by changing the dataset index:
export function dataset_currentIndexChanged(){
if (isFiltered) // Boolean, turns true everytime I use a filter
{
pageNumber = $w("#dataset").getTotalPageCount();
pageScript(pageNumber, 1); // A script that builds the page numbers' buttons
isFiltered = false;
}
}