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

【项目经验】:elementui表格中表头的多选框换成文字

一.项目需求

        表格可以多选,表头都是汉字。。。。类似于这种

        

二.实现功能

  • 用到的方法

Table Attributes
参数说明类型可选值默认值
header-cell-class-name表头单元格的 className 的回调方法,也可以使用字符串为所有表头单元格设置一个固定的 className。Function({row, column, rowIndex, columnIndex})/String

  • 实现代码(可复制直接跑)

HTML部分
<template><div class="Box"><div><el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 500px"@selection-change="handleSelectionChange" :header-cell-class-name="cellClass"><el-table-column type="selection" width="55"></el-table-column><el-table-column label="日期" width="120"><template slot-scope="scope">{{ scope.row.date }}</template></el-table-column><el-table-column prop="name" label="姓名" width="120"></el-table-column><el-table-column prop="address" label="地址" show-overflow-tooltip></el-table-column></el-table></div></div>
</template>
js部分
<script>
export default {name: "list",data () {return {tableData: [{date: '2023-09-03',name: 'bug天选之子',address: 'https://blog.csdn.net/weixin_70245286?spm=1000.2115.3001.5343'}, {date: '2023-09-03',name: 'bug天选之子',address: 'https://blog.csdn.net/weixin_70245286?spm=1000.2115.3001.5343'}, {date: '2023-09-03',name: 'bug天选之子',address: 'https://blog.csdn.net/weixin_70245286?spm=1000.2115.3001.5343'}, {date: '2023-09-03',name: 'bug天选之子',address: 'https://blog.csdn.net/weixin_70245286?spm=1000.2115.3001.5343'},],multipleSelection: [],}},methods: {// 选中的项handleSelectionChange (val) {this.multipleSelection = val;console.log("选中的项:", this.multipleSelection);},// 修改多选框表头cellClass (row) {// 判断第几列if (row.columnIndex === 0) {return "disableSelection";}}},mounted () {}
}
</script>
css部分
<style scoped>
.Box {display: flex;justify-content: center;align-items: center;
}::v-deep.el-table .disableSelection .cell .el-checkbox__inner {display: none;position: relative;
}::v-deep.el-table .disableSelection .cell::before {content: "选项";position: absolute;right: 15px;
}::v-deep.el-table {border: 1px solid blue;
}
</style>
实现后的效果图

三.总结

关键代码

// 在表格上绑定header-cell-class-name属性
<el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 500px"@selection-change="handleSelectionChange" :header-cell-class-name="cellClass">
// 在methods中判断确定是第一列然后给对应的class名
cellClass (row) {// 判断第几列if (row.columnIndex === 0) {return "disableSelection";}}
// css做对应修改// 隐藏多选框表头
::v-deep.el-table .disableSelection .cell .el-checkbox__inner {display: none;position: relative;
}
// 替换后的表头内容(根据需求自行设置)
::v-deep.el-table .disableSelection .cell::before {content: "选项";position: absolute;right: 15px;
}

大家有啥更好的方法评论区留言

http://www.lryc.cn/news/152576.html

相关文章:

  • 【LeetCode】剑指 Offer <二刷>(4)
  • CentOS7查看和关闭防火墙
  • LeetCode 无重复字符的最长子串 打败100%的人
  • Spring Boot中通过maven进行多环境配置
  • python自动化Selenium的使用
  • 大数据课程K13——Spark的距离度量相似度度量
  • Lambda表达式第四版
  • 自定义类加载器
  • 【Redis】Redis 的学习教程(七)之 SpringBoot 集成 Redis
  • Vlan和Trunk
  • java 批量下载将多个文件(minio中存储)压缩成一个zip包
  • nnUNet v2数据准备及格式转换 (二)
  • ant-vue1.78版监听a-modal遮罩层的滚动事件
  • MATLAB中residue函数用法
  • 攻防世界-Caesar
  • 嵌入式开发-lin总线介绍 一.概述
  • 羊城杯-2023-Crypto
  • RabbitMQ快速上手及讲解
  • 使用多线程std::thread发挥多核计算优势(解答)
  • MySQL分页查询详解:优化大数据集的LIMIT和OFFSET
  • 解构赋值、函数默认值
  • 【已解决】Mybatis 实现 Group By 动态分组查询
  • Android修改默认gradle路径
  • 原生JS+canvas实现炫酷背景
  • Linux学习之NAS服务器搭建
  • 分享码云上8个宝藏又有价值的开源图片编辑器
  • TCP Header都有啥?
  • 无涯教程-Android - AutoCompleteTextView函数
  • 【Docker】 07-安装ElasticSearch、Kibana
  • 【数据结构篇】线性表1 --- 顺序表、链表 (万字详解!!)