当前位置: 首页 > news >正文

el-table 列分页

在这里插入图片描述

<template><div><el-table:data="tableData":key="tampTime"style="width: 100%"><el-table-columnprop="name"label="姓名"width="180"></el-table-column><el-table-columnprop="age"label="年龄"width="180"></el-table-column><el-table-columnprop="gender"label="性别"></el-table-column><el-table-columnv-for="(item, index) in showColData":key="index":label="item.colLabel"><template slot="header"><div class="custom-header-cell"><span class="label">{{item.colLabel}}</span><template v-if="colPage.totalPage > 1"><div v-if="!index" :class="['prev-btn', {disabled: colPage.current === 1}]" @click="handlePrev">上一页</div><div v-if="index === showColData.length - 1" :class="['next-btn', {disabled: colPage.current === colPage.totalPage}]" @click="handleNext">下一页</div></template></div></template><template slot-scope="scope">{{ scope.row.colData[item.index].colValue }}</template></el-table-column></el-table></div>
</template><script>export default {data () {return {tableData: [],fullColData: [],showColData: [],colPage: {current: 1,size: 10,totalPage: 0},tampTime: ''}},created () {this.initTableData()},methods: {// 模拟一些数据initTableData () {const result = []for (let i = 0; i < 10; i++) {const obj = {name: '张三',age: 18,gender: '男',colData: []}for (let j = 0; j < 40; j++) {obj.colData.push({colLabel: `${j + 1}`,colValue: `${i + 1}_${j + 1}`})}result.push(obj)}this.tableData = resultthis.initColData()},// 初始化列initColData () {const { tableData, colPage } = thisconst { colData: fullColData } = tableData[0]// 添加索引,用于取数据fullColData.forEach((item, index) => {item.index = index})this.fullColData = fullColDatalet showColData = fullColDataif (fullColData.length > colPage.size) {showColData = fullColData.slice(0, 10)}this.showColData = showColDatathis.colPage.totalPage = Math.ceil(fullColData.length / colPage.size)},// 上一页handlePrev () {let { current } = this.colPageif (current > 1) {current--this.colPage.current = currentthis.changeCellData()}},// 下一页handleNext () {let { current, totalPage } = this.colPageif (current < totalPage) {current++this.colPage.current = currentthis.changeCellData()}this.$forceUpdate()},// 根据页数改变列数据changeCellData () {const { colPage, fullColData } = thisconst startSlice = (colPage.current - 1) * colPage.sizeconst endSlice = startSlice + colPage.sizeconst showColData = fullColData.slice(startSlice, endSlice)this.showColData = showColDatathis.tampTime = new Date().valueOf()}}
}
</script><style lang="scss" scoped>
::v-deep .el-table {// 默认是 hidden 按钮超出会隐藏.el-table__header-wrapper,th.el-table__cell,.cell {overflow: visible;}.custom-header-cell {position: relative;.label {position: relative;z-index: 2;color: #000;}.prev-btn,.next-btn {width: 20px;padding: 6px 0;position: absolute;z-index: 9;top: -12px;background-color: #3f3fbb;color: #fff;text-align: center;font-weight: 400;line-height: 18px;transition: all .4s;&:hover {cursor: pointer;opacity: .8;}&.disabled {cursor: not-allowed;background-color: #a6a7e2;}}.prev-btn {left: -30px;}.next-btn {right: -10px;}}
}
</style>
http://www.lryc.cn/news/220454.html

相关文章:

  • APP攻防--ADB基础
  • 【Linux】第十站:git和gdb的基本使用
  • Single Image Haze Removal Using Dark Channel Prior(暗通道先验)
  • 力扣382.链表随机节点(java利用数组随机返回节点值)
  • 在jupyter中使用R
  • 2023(第四届)江西开放数据创新应用大赛等你来挑战!
  • 2023-mac rz sz 安装
  • 使用Matplotlib绘画3D图时运行不出结果,也不报错,图片是空白 !!
  • Matlab函数——find
  • mac安装python3
  • 【星海出品】VUE(一)
  • Stable Diffusion 的提示词使用技巧
  • Hook函数
  • USB简介系列-01
  • 算法小白的心得笔记:比较小数点后五位,而不会受到浮点数精度问题的影响。
  • 11月起,33个省份纳入数电票开票试点范围内,发票无纸化已是大势所趋!
  • NLP之Bert多分类实现案例(数据获取与处理)
  • matlab中的mapminmax函数初步理解和应用
  • svc和ingress的关系
  • 可以使用以下代码对数据库查询结果进行分组统计
  • win10提示mfc100u.dll丢失的解决方法,快速解决dll问题
  • zookeeper:启动原理
  • kafka问题汇总
  • C#使用随机数模拟英雄联盟S13瑞士轮比赛
  • RabbitMQ(高级特性)利用限流实现不公平分发
  • 3 网络协议入门
  • 【星海出品】VUE(五)
  • 项目实战之安装依赖npm install
  • Java之图书管理系统
  • 用「埋点」记录自己,不妄过一生