当前位置:网站首页>el-table筛选数据
el-table筛选数据
2022-08-06 04:47:00 【Pert-】
- filter-multiple 是否开启多选
- filters 筛选项
- filter-method 筛选条件
- filter-change 筛选条件改变时触发
<!-- 表格部分 -->
<el-table
ref="table"
:data="tableData"
@filter-change="_filterChange"
border
>
<template v-for="(item, index) in dataList">
<el-table-column
sortable
:show-overflow-tooltip="true"
:key="index"
:label="item.label"
align="center"
:prop="item.value"
:filter-multiple="true"
:filters="filterData(item)"
:filter-method="filterTag"
>
</el-table-column>
</template>
</el-table>
1. filter-multiple
是否开启多选
2. filters
filters 接收一个数组对象,label是显示的文字,value是筛选时的数据
这里筛选项根据列表column循环生成的,你也可以手动生成
//计算属性
computed: {
// 筛选项
filterData(){
return function(data){
let obj = [];
//找到对应的数据 并添加到obj
this.tableData.filter(item => {
obj.push({
text:item[data.value],
value:item[data.value]
})
})
//因为column有重复数据,所以要进行去重
return this.deWeight(obj)
}
},
},
//方法
methods: {
// 数组对象去重
deWeight(arr) {
for (var i = 0; i < arr.length - 1; i++) {
for (var j = i + 1; j < arr.length; j++) {
if (arr[i].text == arr[j].text) {
arr.splice(j, 1);
j--;
}
}
}
return arr;
}
},
filterTag
这一步返回符合条件的数据
//返回符合条件的数据
// 参数分别是:选中的条件 、当前行 、当前列
filterTag(value, row, column) {
const property = column['property'];
return row[property] === value;
},
自此就能实现表头筛选功能了
二、筛选数据后获取筛选后的数量
据我查找element好像没有提供这个功能,所以只能手动实现了。所幸element提供了一个方法:@filter-change 当表格的筛选条件发生变化的时候会触发该事件,参数的值是一个对象,对象的 key 是 column 的 columnKey,对应的 value 为用户选择的筛选条件的数组(注意执行时机)
_filterChange() {
this.totalSize = this.$refs.table.tableData.length;
console.log(this.totalSize);
},
边栏推荐
猜你喜欢

首次公开!赛迪顾问《湖仓一体技术研究报告》深入解读

【Image classification】2021-CvT

瑞吉外卖项目实战Day04

MySQL - 事务四大特性、事务隔离级别、事务的脏读、不可重复读、幻读

Bee使用postgresql数据库插入记录后返回ID值

Responsive dream weaving template enterprise group website
![[C language array subscript out of bounds] Infinite loop caused by array subscript out of bounds](/img/43/e6d08594117bf228488bf34b82a6b1.png)
[C language array subscript out of bounds] Infinite loop caused by array subscript out of bounds

正则表达式行尾行首添加字符

解决错误:DispatcherServlet爆红!!

(十)集合 -Set
随机推荐
正则表达式行尾行首添加字符
数学建模学习(77):matlab相关性分析(皮尔逊,肯德尔,斯皮尔曼)
工业机器人复习重点
"Module + antenna" full stack solution, to speed up the Internet of things terminal efficient deployment
Flink-cdc synchronizes mysql data
Datax及Datax-web 下载使用
[Binary tree] The number of nodes whose statistical value is equal to the average value of the subtree
Practical and bytes to beat Flink status query optimization
7. Building RESTful Services
Why is the result of double = 5 / 9; zero
LoRa技术有哪些应用场景?
The LabVIEW application window is always on top
【二叉树】统计值等于子树平均值的节点数
【图像分类】2021-CvT
aws篇8
2023年第六届先进控制,自动化与机器人国际会议(ICACAR 2023)
Translation recommendation|In-depth analysis of BookKeeper protocol model and verification
ESP 特权隔离机制—案例研究
Simple sample code of google's lightweight DI framework guice
A first look at the code to start, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, the first time to run the golang program EP01