element-ui table 的翻页记忆选中
公司中台项目刚开始开发,用了vue+element,需要许多前置调研,table的翻译记忆选中就是其中之一。
template:
<el-table
:ref="tableRef"
:data="tableData"
@select-all="handleSelect"
@select="handleSelect"
>
<el-table-column
type="selection"
width="55"
>
</el-table-column>
<el-table-column
v-for="item in tableColumns"
:key="item"
:property="item.property"
:label="item.label"
:width="item.width"
>
</el-table-column>
</el-table>
<el-pagination
layout="total,prev, pager, next, jumper"
:page-size="5"
@current-change="handleCurrentChange"
:current-page.sync="currentPage"
:total="10">
</el-pagination>
tableRef 是上级传入的props,为了区分多个表格同时存在的情况。
tableData 和 tableColumns 都是从组件外传入的,不难理解。
将 select 和 select-all 事件集中到同一个事件 handleSelect, 因为用到的数据都是该事件返回的 row 。
翻页的 currentPage 和 handleCurrentChange 是翻页组件的当前页和页码改变的事件。
methods:
handleSelect(val){
const hasSave = this.selected.find(item => {
return item.page === this.currentPage
})
if(hasSave){
hasSave.rows = this.tableData.filter(item => {
return val.includes(item)
})
}else{
this.selected.push({
page: this.currentPage,
rows: val
})
}
},
handleCurrentChange(val){
// 向上传递事件
this.$emit('pageChange',val)
},
toggleSelection(){
this.$refs[this.tableRef].clearSelection()
const target = this.selected.find(item => {
return item.page === this.currentPage
})
if(!target) return
const rows = target.rows
if(rows && rows.length>0){
this.$nextTick(()=>{
rows.forEach(row => {
this.$refs[this.tableRef].toggleRowSelection(row)
})
})
}
},
getSelected(){
if(this.selected.length === 0){
return []
}
let result = []
this.selected.forEach(item => {
result = [...result,...item.rows]
})
return result
}
当页码改变时,传递数据到外层请求数据,在本组件watch tableData的变化
watch: {
tableData(){
this.toggleSelection()
}
},
最后获取执行具体逻辑就不解释了,都是比较简单的,有需要可以留言或者私信。
element-ui table 的翻页记忆选中的更多相关文章
- Vue+element ui table 导出到excel
需求: Vue+element UI table下的根据搜索条件导出当前所有数据 参考: https://blog.csdn.net/u010427666/article/details/792081 ...
- element ui 表格提交时获取所有选中的checkbox的数据
<el-table ref="multipleTable" :data="appList" @selection-change="changeF ...
- VUE -- 对 Element UI table中数据进行二次处理
时间——日期 后台经常给我们返回的是 时间戳 (例如:1535620671) 这时候我们页面展现的时候需要将时间戳转换为我们要的格式 例如 (YYYY-MM-DD HH:mm:ss) 如果是在Elem ...
- Vue 基于node npm & vue-cli & element UI创建vue单页应用
基于node npm & vue-cli & element UI创建vue单页应用 开发环境 Win 10 node-v10.15.3-x64.msi 下载地址: https ...
- Element UI table组件源码分析
本文章从如下图所示的最基本的table入手,分析table组件源代码.本人已经对table组件原来的源码进行削减,源码点击这里下载.本文只对重要的代码片段进行讲解,推荐下载代码把项目运行起来,跟着文章 ...
- Element UI table参数中的selectable的使用
Element UI table参数中的selectable的使用中遇到的坑:页面: <el-table-column :selectable='selectable' type="s ...
- Element ui 中使用table组件实现分页记忆选中
我们再用vue和element-ui,或者其他的表格的时候,可能需要能记忆翻页勾选,那么实现以下几个方法就ok了 示例如下 <el-table :data="tableData&quo ...
- element UI table 过滤 筛选问题
一.问提描述 使用elementUI table 官方筛选案例,发现筛选不是服务器端筛选,而是浏览器端对每一页进行单独筛选. 如何在服务器端筛选? 二.查询Element UI 官网table组 ...
- element ui table 导出excel表格
https://blog.csdn.net/u010427666/article/details/79208145 vue2.0 + element UI 中 el-table 数据导出Excel1. ...
随机推荐
- spring+springMVC+Mybatis架构下采用AbstractRoutingDataSource、atomikos、JTA实现多数据源灵活切换以及分布式事务管理
背景: 1.系统采用SSM架构.需要在10多个MYSQL数据库之间进行切换并对数据进行操作,上篇博文<springMVC+Mybatis(使用AbstractRoutingDataSource实 ...
- Visual Studio中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法
解决方案:选中项目中引入的dll,鼠标右键,选择属性,把“嵌入互操作类型”设置为False,问题轻松解决. 问题分析: 1.”嵌入互操作类型”中的嵌入就是引进.导入的意思,类似于c#中using,c中 ...
- VS开发ArcEngine时的一个异常信息——“ArcGIS version not specified. You must call RuntimeManager.Bind before creating any ArcGIS components.”
问题描述:程序报错“ArcGIS version not specified. You must call RuntimeManager.Bind before creating any ArcGIS ...
- Mysql 数据库优化(一)
一 避免网页访问错误 1 数据库连接timeout产生页面5xx错误 2 慢查询造成页面无法加载 3 阻塞造成数据无法提交 二 增加数据库的稳定性 三 优化用户体验 1 流畅的页面访问速度 2 良好 ...
- oracle函数 dbtimezone
[功能]:返回时区 [参数]:没有参数,没有括号 [返回]:字符型 [示例]select dbtimezone from dual;
- 关于python 中的__future__模块
Python的每个新版本都会增加一些新的功能,或者对原来的功能作一些改动.有些改动是不兼容旧版本的,也就是在当前版本运行正常的代码,到下一个版本运行就可能不正常了. 具体说来就是,某个版本中出现了某个 ...
- 设置 Tomcat 的JVM运行内存
win7,64位: Tomcat7.0.5:jdk1.7: 情况一:Tomcat注册成系统服务,如何修改JVM运行内存? WINDOW 64位 , cmd打开注册表(regedit) HKEY_LOC ...
- 异常解决:java.lang.IllegalStateException: Failed to introspect Class
java.lang.IllegalStateException: Failed to introspect Class 异常详情 原因 解决办法 异常详情 Exception encountered ...
- Spring Boot 动态数据源(多数据源自动切换)
本文实现案例场景: 某系统除了需要从自己的主要数据库上读取和管理数据外,还有一部分业务涉及到其他多个数据库,要求可以在任何方法上可以灵活指定具体要操作的数据库. 为了在开发中以最简单的方法使用,本文基 ...
- H3C 帧中继显示与调试