I'm using the b-table from BootstrapVue with pagination. However, whenever I change pages, the items received from my REST API do not display, even though they are present. I have added a watcher to detect changes in the items array, and the console inside the watcher works as expected. The first page displays the items correctly, but subsequent pages do not. However, if I go back to the first page, the previously empty b-table loads the items.
After researching, I found that this is a known limitation:
b-table doesn't always know if the items being replaced (specifically when using external pagination) are from the same table or if the items array changes (i.e., to new data altogether). It must clear the selected items array whenever anything changes the table's context (sorting, filtering, pagination, table refresh, etc.).
My Current Implementation:
<b-table
v-if="showTable"
id="my-table1"
:items="tableItems"
:fields="fields"
:busy="isBusy"
:per-page="limit"
:current-page="currentPage"
stacked="md"
table-class="padding"
:tbody-tr-class="rowClass"
show-empty
small
responsive
hover
borderless
selectable
>
</b-table>
Script:
props: {
fields: {
type: Array,
default: () => []
},
items: {
type: Array,
default: () => []
},
totalRows: {
type: Number,
default: 0
},
isBusy: {
type: Boolean,
default: false
},
},
data() {
return {
currentPage: 1,
limit: 5,
tableItems: [],
selectedRows: [],
};
},
watch: {
items: {
handler(newItems) {
console.log("\n \n items changed", newItems);
this.updateTableItems(newItems);
},
},
},
methods: {
updateTableItems(newItems) {
this.tableItems = [];
this.$nextTick(() => {
this.tableItems = [...newItems];
});
},
changePage(page) {
this.currentPage = page;
this.$emit("pageChange", (page - 1) * this.limit, this.limit);
}
}
Issue:
- When switching pages items are not displaying.
How can I persist pagination in b-table? Any guidance or workaround would be greatly appreciated!