Pagination - change currentPage?

Hello,

first time poster, greetings to all!
Of course right away with a problem :wink:

I have a repeater connected to a database and a pagination. On the live website everything works. I now want to change the page via velo (there are 3 pages). With the following code the currentpage is set to 2, but it still shows the first page:

$w(“#dynamicDataset”).onReady(() => {
$w(“#pagination”).currentPage = 2
});

If someone could help me, that would be great…

Greetings, Spectral

Hi,

unfortunately, I have not made any progress here.

When I change the page via pagination via code, console.log shows me the new value, but the page doesn’t change (the pagination bar display doesn’t change either).

Any tips would be greatly appreciated!

Thank you & best regards, Spectral

Hi,

I have now found the first problem after all.

I filter the dataset beforehand:
$w(“#dynamicDataset”).setFilter(wixData.filter()
(…)
)
This prevents the page (set with .currentPage) from being displayed on the Pagination Bar.
But I do not know why?

Without this filtering, the correct page will be displayed on the pagination bar, but not yet by the connected repeater. In the velo Reference at .totalPages it says “If the pagination bar is connected to a dataset, it is recommended that you allow the dateset to control the pagination bar’s totalPages value.”. What is meant by this?

Again any help would be appreciated, Spectral

Hello Spectral,
Greetings to you too, and welcome to the community!
Regarding your issue with setting the current page for the repeater using Velo (formerly known as Corvid), there might be a reason why the page isn’t changing as expected. The code you provided seems correct, so let’s explore a few possibilities:

  1. Pagination Configuration: Ensure that the pagination element (“#pagination”) is properly connected to the repeater (“#dynamicDataset”) and that the pagination is set up correctly with the appropriate settings (total number of pages, items per page, etc.).
  2. Velo Execution Timing: Make sure the code is running at the appropriate time. If the repeater or pagination elements are dependent on data from a dynamic dataset, ensure that the code is executed after the dataset has loaded the data. If it’s a static dataset, make sure the code runs when the repeater is fully rendered and ready.
  3. Data Synchronization: Double-check that the data in the database is consistent with the pagination setup. If the number of items in the dataset changes or if there are any issues with data retrieval, it might affect the pagination behavior.
  4. Custom Pagination: If you have implemented custom pagination logic, make sure that it doesn’t interfere with the default behavior of the pagination element.
  5. Page Index: Remember that the currentPage property is 1-based (not 0-based), so setting it to 2 should show the second page, not the first.
    For further debugging, you can use the browser console (usually accessible by pressing F12) to check for any errors or logs when the page is loaded or when the code runs.
    If the issue persists, providing more context or a code snippet of the pagination setup and relevant Velo code might help the community assist you better.
    Best of luck with resolving the issue, and I hope you have a great experience with Velo and your Wix website! If you have any more questions or need further assistance, feel free to ask. Happy coding!

Securitas ePay

Hi tannaowen.s6 ,

thanks for the kind response.

  • 1 - The pagination element is properly connected to the repeater

  • 2 - I use “$w.onReady(async function () { … })” and then “$w(”#dynamicDataset").onReady() => { … })". See code. This should avoid timing issues, right?

  • 3 - I do not use a custom pagination setup.

  • 4 - See 3

  • 5 - I know…

Here is the relevant code:

$w.onReady(async function () {

    $w("#dynamicDataset").setFilter(wixData.filter()
            .contains("title", $w('#searchBar').value)
            .contains("kategorie", Haupt_Kategorie)
            .or(
                wixData.filter()
                .contains("subtitle", $w('#searchBar').value)
                .contains("kategorie", Haupt_Kategorie)
            )
        )
        .then(() => {
            count();
        })

    let tmp6 = await session.getItem(Paginierung_Memory);
    if (tmp6 === null) { tmp6 = "1" }
    $w("#dynamicDataset").onReady(() => {
        $w("#pagination").currentPage = Number(tmp6);
        console.log("currentPage: " + $w("#pagination").currentPage)
    });

    $w("#pagination").onChange(() => {
        let Paginierung = $w("#pagination").currentPage;
        session.setItem(Paginierung_Memory, Paginierung);
    });

)};

I want to cache the last selected pagnination page and retrieve it when I return to the website. Without the first code block with “.setFilter” at least .currentPage displays the correct page in the Pagination Bar. With the “.setFilter” code block in front there is no change in the pagination bar. The function “count” has no effect on this. The correct page is always output by console.log.

Thx for help, Spectral

push… one more try if someone can help me?

Behind a filter (on the repeater)
$w(“#dynamicDataset”).setFilter (…)
calling a page in the pagination bar does not work anymore:
$w(“#pagination”).currentPage = (…)

What am I doing wrong?

Thaaaanks, Spectral!