question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pagination show wrong page of table

See original GitHub issue

Describe the bug

I have a problem with the pagination of a table who get it’s content from a provider function, which uses ctx.currentPage and ctx.perPage to limit the data.

I store the currentPage, perPage and totalRows in a localstorage whenever it changes using a watch function:

watch: {
  perPage(newValue, oldValue) {
    localStorage.setItem('perPage', JSON.stringify(newValue));
  },
  currentPage(newValue, oldValue) {
    localStorage.setItem('currentPage', JSON.stringify(newValue));
  },
  totalRows(newValue, oldValue) {
    localStorage.setItem('totalRows', JSON.stringify(newValue));
  },
}

And restore it like this:

mounted() {
   this.perPage = JSON.parse(localStorage.getItem('perPage')) || 10;
   this.totalRows = JSON.parse(localStorage.getItem('totalRows')) || 0;
   this.currentPage = JSON.parse(localStorage.getItem('currentPage')) || 1;
}

My provider function:

async provider(ctx) {
      this.isBusy = true;
      try {
        return await itemsApi.fetchItems('https://domain.xyz/entrypoint', {
          currentPage: ctx.currentPage,
          perPage: ctx.perPage
        }).then((result) => {
          this.isBusy = false;
          this.totalRows = result.totalRows;
          return result.data;
        });
      } catch (error) {
        this.isBusy = false;
        this.totalRows = 0;
        this.currentPage = 1;
        return [];
      }
    },

The data section:

data() {
    return {
      isBusy: false,
      perPage: 10,
      currentPage: 1,
      totalRows: 0,
   }
}

The table / pagination markup:

<b-table
        :items="provider"
        :fields="filteredFields"
        primary-key="uid"
        :busy.sync="isBusy"
        :current-page="currentPage"
        :per-page="perPage"
    />
<b-pagination
        first-number
        last-number
        v-model="currentPage"
        :total-rows="totalRows"
        :per-page="perPage"
    />

Every record has an edit link, who brings the user to a different url (it’s not a single page application).

If the user goes back to the list page with the table, all limit settings will be restored from the localstorage correctly and the table also loads the correct section (e.g. records 11 - 20, if he/she was on page 2 before). Unfortunately the pagination always shows page 1 – indepenent from the value in currentPage. If the user clicks on page 2 of the pagination nothings happens, because he/she is already on page 2.

This problem is very annoying, especially if the table has a lot of pages and the user needs to come back to the previously visited page.

Steps to reproduce the bug

Like described

Expected behavior

The pagination should show the loaded currentPage

Versions

Libraries:

  • BootstrapVue: 2.21.2
  • Bootstrap: 4.6.0
  • Vue: 2.6.14

Environment:

  • Device: Mac
  • OS: macOS Big Sur
  • Browser: Firefox / Chrome / Edge / Safari
  • Version: 89 / 91 / 91 / 14.1.1

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rezaffmcommented, Oct 27, 2022

Any solution?

1reaction
mediaessenzcommented, Jul 2, 2021

This works, but results in two requests to the data entry point.

  1. with currentPage: 1
  2. with currentPage restored from localStorage

I have added a console.log to the provider function to demonstrate this behaviour.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Datatable showing wrong page numbers - Stack Overflow
Currently we are having total 9 records but pagination is showing as 5 pages. After clicking on another page, it displays previous record....
Read more >
Paging not showing correct number of pages - DataTables
I am doing a server side data fetch which is returning the correct number of rows and totalPages, however, the number of buttons...
Read more >
Tabel of contents shows wrong page numbers
I have a problem with my table of contents. The appendix shows the pagenumbers out of order. I think this is because I...
Read more >
Pagination does not work correctly when data is changed
After updating table data, when I use pagination, it does not show me the latest updated data, instead it reverts to the previous...
Read more >
Microsoft Word: Incorrect Page Number Shows in Table of ...
http://www.seriousscholar.com/get-academic-writing-tips.htmlIn a sample Word document with a table of contents and list of tables, I show a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found