pagination show wrong page of table
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:9 (2 by maintainers)
Top GitHub Comments
Any solution?
This works, but results in two requests to the data entry point.
I have added a console.log to the provider function to demonstrate this behaviour.