Vue el-table-column filters
时间: 2023-11-29 18:46:03 浏览: 232
Vue 的 Element UI 框架中的 el-table-column 组件提供了 filters 和 filter-method 属性,用于在表格中添加筛选功能。具体实现步骤如下:
1. 在 el-table-column 组件上设置 filters 和 filter-method 属性,其中 filters 为筛选项数组,filter-method 为筛选方法。
2. 在 filter-method 方法中,根据筛选条件对数据进行过滤,并返回过滤后的数据。
下面是一个示例代码,演示如何在 Vue 的 el-table 中使用 filters:
```html
<template>
<el-table :data="tableData">
<el-table-column prop="name" label="姓名" :filters="filters" :filter-method="filterMethod"></el-table-column>
<el-table-column prop="age" label="年龄"></el-table-column>
<el-table-column prop="gender" label="性别"></el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{ name: '张三', age: 18, gender: '男' },
{ name: '李四', age: 20, gender: '女' },
{ name: '王五', age: 22, gender: '男' },
{ name: '赵六', age: 24, gender: '女' }
],
filters: [
{ text: '男', value: '男' },
{ text: '女', value: '女' }
]
}
},
methods: {
filterMethod(value, row) {
return row.gender === value;
}
}
}
</script>
```
在上面的代码中,我们在 el-table-column 组件上设置了 filters 和 filter-method 属性,其中 filters 为筛选项数组,filter-method 为筛选方法。在 filterMethod 方法中,我们根据筛选条件对数据进行过滤,并返回过滤后的数据。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)