我正在使用Vue-good-table远程搜索,当我在第二页搜索时,我遇到了一个问题。搜索页自动设置为第二页,但分页设置为第一页。我试着用setCurrentPage手动设置页面,但不起作用。这是我的代码。
<vue-good-table
mode="remote"
:line-numbers="true"
:search-options="{
enabled: true,
placeholder: 'Search this table',
searchFn: searchTbl
}"
:select-options="{
enabled: true,
selectionInfoClass: 'table-alert__box'
}"
:pagination-options="{
enabled: true,
mode: 'records'
}"
style-class="tableOne vgt-table"
:rows="rows"
@on-selected-rows-change="selectionChanged"
:columns="columns"
@on-page-change="onPageChange"
:total-rows="totalRecords"
@on-sort-change="onSortChange"
@on-column-filter="onColumnFilter"
@on-per-page-change="onPerPageChange"
@on-search="searchTbl"
>
<div slot="table-actions" class="mb-3">
<b-button class="form-btn" type="submit" variant="success" @click="loadItems">Refresh</b-button>
</div>
<div slot="selected-row-actions" class="mb-3">
<b-button variant="danger">Delete</b-button>
</div>
<template slot="table-row" slot-scope="props">
<span v-if="props.column.field == 'button'">
<a href @click.prevent="editRecord(props.row)">
<i class="i-Eraser-2 text-25 text-success mr-2" />
{{ props.row.button }}
</a>
<a href @click.prevent="confirmMsg(props.row)">
<i class="i-Close-Window text-25 text-danger" />
{{ props.row.button }}
</a>
</span>
</template>
</vue-good-table>data() {
return {
pagination:{
enabled: true,
mode: 'records',
setCurrentPage: 1,
}
}
}这是对表函数的搜索和数据加载,使用loadItems函数,我设置了setCurrentPage的值,它设置得很正确。
searchTbl(searchTerm){
this.updateParams({
columnFilters: {
search: searchTerm,
},
});
this.loadItems()
},
loadItems() {
this.pagination.setCurrentPage = this.ahStore.tblData.currentPage;
console.log(this.pagination.setCurrentPage)
this.$store.dispatch('getFromServer', this.serverParams)
.then((response) => {
this.totalRecords = this.ahStore.tblData.totalRecords;
this.rows = this.ahStore.tblData.rows;
})
.catch((err) => {
console.log(err)
});
},发布于 2020-04-16 17:49:53
我做了一个简单的解决方案,只需用searchTbl函数传递this.serverParams.page = 1即可。现在它被自动设置为第一页。
https://stackoverflow.com/questions/61244627
复制相似问题