# Pagination function not working even though there are more than 2 items in dataset

**URL:** <https://forum.wixstudio.com/t/pagination-function-not-working-even-though-there-are-more-than-2-items-in-dataset/74419>\
**Category:** Ask the community\
**Tags:** code, wix, wix-studio, question\
**Created:** [October 22, 2025, 3:01am UTC](https://forum.wixstudio.com/t/pagination-function-not-working-even-though-there-are-more-than-2-items-in-dataset/74419 "2025-10-22T03:01:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aquarius\_Mike](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/aquarius_mike/32/86255_2.png) [@Aquarius\_Mike](https://forum.wixstudio.com/u/Aquarius_Mike)\
**Post date:** [October 22, 2025, 3:01am UTC](https://forum.wixstudio.com/t/pagination-function-not-working-even-though-there-are-more-than-2-items-in-dataset/74419/1 "2025-10-22T03:01:23Z")

</div>

```javascript
const linkField = "link-ourcourses-1-title"; // replace this value

$w.onReady(function () {
  $w("#dynamicDataset").onReady(() => {
    const numberOfItems = $w("#dynamicDataset").getTotalCount();

    $w("#dynamicDataset")
      .getItems(0, numberOfItems)
      .then((result) => {
        const dynamicPageURLs = result.items.map((item) => item[linkField]);
        local.setItem("dynamicPageURLs", dynamicPageURLs);
      })
      .catch((err) => {
        console.log(err.code, err.message);
      });
  });
});
$w.onReady(function () {
  $w("#preBtn").disable();
  $w("#nextBtn").disable();

  if (local.getItem("dynamicPageURLs")) {
    const dynamicPageURLs = local.getItem("dynamicPageURLs").split(",");

    const currentPage =
      "/" +
      wixLocationFrontend.prefix +
      "/" +
      wixLocationFrontend.path.join("/");
    const currentPageIndex = dynamicPageURLs.indexOf(currentPage);

    if (currentPageIndex > 0) {
      $w("#preBtn").link = dynamicPageURLs[currentPageIndex - 1];
      $w("#preBtn").enable();
    }

    if (currentPageIndex < dynamicPageURLs.length - 1) {
      $w("#nextBtn").link = dynamicPageURLs[currentPageIndex + 1];
      $w("#nextBtn").enable();
    }
  }
});

```

it can change to next item sometimes, but the previous item button is not working. Anyone knows how to fix it?

---

<div class="post-metadata">

**Author:** ![KEYBOARD-WARRIOR](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@KEYBOARD-WARRIOR](https://forum.wixstudio.com/u/KEYBOARD-WARRIOR)\
**Post date:** [October 22, 2025, 7:18am UTC](https://forum.wixstudio.com/t/pagination-function-not-working-even-though-there-are-more-than-2-items-in-dataset/74419/2 "2025-10-22T07:18:21Z")

</div>

Question: Why do you use 2x –\> $w.onReady() ??? –\> You have only one page.

Ask yourself –\> **WHAT DOES MEAN –\> $w.onReady() ← exactly?**

Could it be, that your SETUP has timing problems because of the 2x $w.onReady() ???

Try ….

```javascript
import wixLocationFrontend from 'wix-location-frontend';
import { local } from 'wix-storage';

$w.onReady(function () {
  const linkField = "link-ourcourses-1-title"; // replace this value
  const dataset = $w("#dynamicDataset");

  dataset.onReady(() => {
    const totalCount = dataset.getTotalCount();

    dataset.getItems(0, totalCount)
      .then((result) => {
        const dynamicPageURLs = result.items.map((item) => item[linkField]);
        local.setItem("dynamicPageURLs", dynamicPageURLs.join(","));

        const currentPage = "/" + wixLocationFrontend.prefix + "/" + wixLocationFrontend.path.join("/");
        const currentIndex = dynamicPageURLs.indexOf(currentPage);

        // Disable both by default
        $w("#preBtn").disable();
        $w("#nextBtn").disable();

        // Enable previous
        if (currentIndex > 0) {
          $w("#preBtn").link = dynamicPageURLs[currentIndex - 1];
          $w("#preBtn").enable();
        }

        // Enable next
        if (currentIndex < dynamicPageURLs.length - 1) {
          $w("#nextBtn").link = dynamicPageURLs[currentIndex + 1];
          $w("#nextBtn").enable();
        }
      })
      .catch((err) => console.log("Error:", err));
  });
});

```
