首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分页在vue-good-table中不能与搜索一起使用

分页在vue-good-table中不能与搜索一起使用
EN

Stack Overflow用户
提问于 2020-04-16 15:14:19
回答 1查看 909关注 0票数 0

我正在使用Vue-good-table远程搜索,当我在第二页搜索时,我遇到了一个问题。搜索页自动设置为第二页,但分页设置为第一页。我试着用setCurrentPage手动设置页面,但不起作用。这是我的代码。

代码语言:javascript
复制
<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>
代码语言:javascript
复制
data() {
            return {
                pagination:{
                    enabled: true,
                    mode: 'records',
                    setCurrentPage: 1,
                }
             }
      }

这是对表函数的搜索和数据加载,使用loadItems函数,我设置了setCurrentPage的值,它设置得很正确。

代码语言:javascript
复制
    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)

                    });
            },
EN

回答 1

Stack Overflow用户

发布于 2020-04-16 17:49:53

我做了一个简单的解决方案,只需用searchTbl函数传递this.serverParams.page = 1即可。现在它被自动设置为第一页。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61244627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档