el-table分页--保留复选框勾选状态,查询--清空勾选状态

1,表格

  <el-table
        :data="tableData"
        ref="multipleTable"
        row-key="id"    // 1,加id
        stripe
        style="width: 100%;"
        v-loading="tableLoading"
        @selection-change="handleSelectionChange"  //2,该方法的参数为选中的rows
      >
      <el-table-column
      type="selection"
      reserve-selection   // 3,加上该参数,保留勾选状态
      width="55">
    </el-table-column>
      //------- 以下为自定义插槽--全选,当页------
        <!-- <el-table-column width="100" fixed :reserve-selection="true">
          <template #header>
            <el-checkbox v-model="selectPage" @change="selectPageMethod()" 
      :disabled="selectAll">
              {{ $t("common.selectCurrentPage") }}
            </el-checkbox>
            <el-checkbox
              v-model="selectAll"
              @change="selectAllMethod('handle')"
              :disabled="selectPage"
            >
              {{ $t("common.selectAll") }}
            </el-checkbox>
          </template>
          <template slot-scope="scope">
            <el-checkbox
              v-model="scope.row.checked"
              @change="checkSingle(scope.row)"
            />
          </template>
        </el-table-column> -->
        <el-table-column prop="companyCode" label="公司"  show-overflow-tooltip>
        </el-table-column>   
      </el-table>
     //分页组件需要自定义
      <pagination
        v-show="paginationInfo.totalCount > 0"
        :total="paginationInfo.totalCount"
        :page.sync="paginationInfo.currentPage"
        :limit.sync="paginationInfo.pageSize"
        @pagination="paginationChange"
      />

清空复选框勾选状态调用表格上的方法:

 this.$refs.multipleTable.clearSelection();

2,自定义分页组件

<template>
  <div :class="{'hidden':hidden}" class="pagination-container">
    <el-pagination
      :background="background"
      :current-page.sync="currentPage"
      :page-size.sync="pageSize"
      :layout="layout"
      :page-sizes="pageSizes"
      :total="total"
      v-bind="$attrs"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { scrollTo } from '@/utils/scroll-to'

export default {
  name: 'Pagination',
  props: {
    total: {
      required: true,
      type: Number
    },
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 20
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50]
      }
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper'
    },
    background: {
      type: Boolean,
      default: true
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      this.$emit('pagination', { page: this.currentPage, limit: val })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    },
    handleCurrentChange(val) {
      this.$emit('pagination', { page: val, limit: this.pageSize })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    }
  }
}
</script>

<style scoped>
.pagination-container {
  background: #fff;
  padding: 10px 16px;
}
.pagination-container.hidden {
  display: none;
}
</style>

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值