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

vue3使用Ant-Design组件a-table表格实现多层表头及合并单元格

vue3使用Ant-Design组件a-table表格实现多层表头及合并单元格

效果图:
在这里插入图片描述
多层表头: 通过columns中的children来设置多个值实现多层表头;

表身单元格合并: 从图中可以看出第一列(班次)和最后一列(值班员签名)需要表格行合并单元格(通过表格的某个字段中相同值进行合并);

整体代码如下:

<template><div class="tableContent"><a-table :columns="columns" :data-source="dataSource" bordered size="small" :pagination="false":scroll="{ y: 640 }"></a-table></div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
const columns = [{title: '班次',dataIndex: 'tableTime',key: 'tableTime',width: 50,align: 'center',customCell: ({ rowSpan }) => {return {rowSpan: rowSpan}}},{title: '时间',dataIndex: 'time',key: 'time',width: 100,align: 'center'},{title: '直供井',children: [{title: 'PH',dataIndex: 'PH1',key: 'PH1',width: 80,align: 'center'},{title: '浊度(NTU)',dataIndex: 'turbidity1',key: 'turbidity1',width: 80,align: 'center'},{title: '电导率(μs/cm)',dataIndex: 'conductivity1',key: 'conductivity1',width: 80,align: 'center'},{title: '温度(°C)',dataIndex: 'temperature1',key: 'temperature1',width: 80,align: 'center'},{title: '余氯(mg/L)',dataIndex: 'residual1',key: 'residual1',width: 80,align: 'center'},],},{title: '出厂水',children: [{title: 'PH',dataIndex: 'PH2',key: 'PH2',width: 80,align: 'center'},{title: '浊度(NTU)',dataIndex: 'turbidity2',key: 'turbidity2',width: 80,align: 'center'},{title: '电导率(μs/cm)',dataIndex: 'conductivity2',key: 'conductivity2',width: 80,align: 'center'},{title: '温度(°C)',dataIndex: 'temperature2',key: 'temperature2',width: 80,align: 'center'},{title: '余氯(mg/L)',dataIndex: 'residual2',key: 'residual2',width: 80,align: 'center'},],},{title: '管网末梢水',children: [{title: 'PH',dataIndex: 'PH3',key: 'PH3',width: 80,align: 'center'},{title: '浊度(NTU)',dataIndex: 'turbidity3',key: 'turbidity3',width: 80,align: 'center'},{title: '电导率(μs/cm)',dataIndex: 'conductivity3',key: 'conductivity3',width: 80,align: 'center'},{title: '温度(°C)',dataIndex: 'temperature3',key: 'temperature3',width: 80,align: 'center'},{title: '余氯(mg/L)',dataIndex: 'residual3',key: 'residual3',width: 80,align: 'center'},],},{title: '值班员签名',dataIndex: 'signature',key: 'signature',width: 100,align: 'center',customCell: ({ rowSpan }) => {return {rowSpan: rowSpan}}},
];
const dataSource = ref([{ tableTime: '早班', time: 1, PH1: 7.61, turbidity1: 0.32, conductivity1: 671.61, temperature1: 23.73, residual1: 0.02, PH2: 7.61, turbidity2: 0.32, conductivity2: 671.61, temperature2: 23.73, residual2: 0.02, PH3: 7.61, turbidity3: 0.32, conductivity3: 671.61, temperature3: 23.73, residual3: 0.02, signature: '张三' },{ tableTime: '早班', time: 2, PH1: 7.61, turbidity1: 0.32, conductivity1: 671.61, temperature1: 23.73, residual1: 0.02, PH2: 7.61, turbidity2: 0.32, conductivity2: 671.61, temperature2: 23.73, residual2: 0.02, PH3: 7.61, turbidity3: 0.32, conductivity3: 671.61, temperature3: 23.73, residual3: 0.02, signature: '张三' },{ tableTime: '中班', time: 9, PH1: 7.61, turbidity1: 0.32, conductivity1: 671.61, temperature1: 23.73, residual1: 0.02, PH2: 7.61, turbidity2: 0.32, conductivity2: 671.61, temperature2: 23.73, residual2: 0.02, PH3: 7.61, turbidity3: 0.32, conductivity3: 671.61, temperature3: 23.73, residual3: 0.02, signature: '李四' },{ tableTime: '中班', time: 10, PH1: 7.61, turbidity1: 0.32, conductivity1: 671.61, temperature1: 23.73, residual1: 0.02, PH2: 7.61, turbidity2: 0.32, conductivity2: 671.61, temperature2: 23.73, residual2: 0.02, PH3: 7.61, turbidity3: 0.32, conductivity3: 671.61, temperature3: 23.73, residual3: 0.02, signature: '李四' },{ tableTime: '中班', time: 11, PH1: 7.61, turbidity1: 0.32, conductivity1: 671.61, temperature1: 23.73, residual1: 0.02, PH2: 7.61, turbidity2: 0.32, conductivity2: 671.61, temperature2: 23.73, residual2: 0.02, PH3: 7.61, turbidity3: 0.32, conductivity3: 671.61, temperature3: 23.73, residual3: 0.02, signature: '李四' },{ tableTime: '晚班', time: 17, PH1: 7.61, turbidity1: 0.32, conductivity1: 671.61, temperature1: 23.73, residual1: 0.02, PH2: 7.61, turbidity2: 0.32, conductivity2: 671.61, temperature2: 23.73, residual2: 0.02, PH3: 7.61, turbidity3: 0.32, conductivity3: 671.61, temperature3: 23.73, residual3: 0.02, signature: '王五' },{ tableTime: '晚班', time: 18, PH1: 7.61, turbidity1: 0.32, conductivity1: 671.61, temperature1: 23.73, residual1: 0.02, PH2: 7.61, turbidity2: 0.32, conductivity2: 671.61, temperature2: 23.73, residual2: 0.02, PH3: 7.61, turbidity3: 0.32, conductivity3: 671.61, temperature3: 23.73, residual3: 0.02, signature: '王五' },
])//合并单元格方法
function groupData(data) {let currentTableTime = '';let currentSignature = '';return data.map((item, index) => {if (currentTableTime !== item.tableTime || currentSignature !== item.signature) {currentTableTime = item.tableTime;currentSignature = item.signature;let rowSpan = 0;for (let i = 0; i < data.length; i++) {if (i >= index) {const currentItem = data[i];if (currentTableTime === currentItem.tableTime && currentSignature === currentItem.signature) {rowSpan += 1;} else {break;}}}item.rowSpan = rowSpan;} else {item.rowSpan = 0;}return item;});
}
groupData(dataSource.value)
</script>
<style lang="less" scoped></style>

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • JavaWeb-JS
  • pycharm画图猫和老鼠
  • Jenkins配置(插件/角色/凭证)
  • 文章解读与仿真程序复现思路——电力自动化设备EI\CSCD\北大核心《考虑分布式光伏高效消纳与负荷损失最小的区域配电网应急资源协同配置策略》
  • 力扣 滑动窗口题目总结
  • javaEE—图书管理系统(基础代码版)
  • 基于Vue的应届毕业生财务管理系统-计算机毕业设计源码82886
  • Android 通过adb命令查看设备尺寸和设置
  • 代码随想录算法训练营第四十一天 | 理论基础、509. 斐波那契数、70. 爬楼梯、746. 使用最小花费爬楼梯
  • 记一次绕过宝塔防火墙的BC站渗透
  • 美颜技术揭秘:美颜SDK与美颜接口的开发实践
  • MySQL——数据库和表的基本操作(一)数据库基础知识
  • SCSS入门指南:基本语法与高效用法
  • xshell7和XFTP个人免费版官方下载免激活
  • 【Python数据分析】基于自回归积分滑动平均模型的疫情分析报告 附完整python代码
  • ➹使用webpack配置多页面应用(MPA)
  • git 常用命令
  • JavaScript-Array类型
  • Laravel深入学习6 - 应用体系结构:解耦事件处理器
  • node入门
  • passportjs 源码分析
  • TCP拥塞控制
  • 从伪并行的 Python 多线程说起
  • 关于for循环的简单归纳
  • 如何学习JavaEE,项目又该如何做?
  • 使用parted解决大于2T的磁盘分区
  • 优化 Vue 项目编译文件大小
  • 原生 js 实现移动端 Touch 滑动反弹
  • scrapy中间件源码分析及常用中间件大全
  • 我们雇佣了一只大猴子...
  • #mysql 8.0 踩坑日记
  • (1)(1.13) SiK无线电高级配置(六)
  • (1)Android开发优化---------UI优化
  • (2)nginx 安装、启停
  • (C#)一个最简单的链表类
  • (zt)基于Facebook和Flash平台的应用架构解析
  • (代码示例)使用setTimeout来延迟加载JS脚本文件
  • (附源码)ssm高校志愿者服务系统 毕业设计 011648
  • (排序详解之 堆排序)
  • (三十五)大数据实战——Superset可视化平台搭建
  • (四)进入MySQL 【事务】
  • (转)母版页和相对路径
  • **登录+JWT+异常处理+拦截器+ThreadLocal-开发思想与代码实现**
  • .net 按比例显示图片的缩略图
  • .NET 的静态构造函数是否线程安全?答案是肯定的!
  • .net 反编译_.net反编译的相关问题
  • .Net7 环境安装配置
  • .py文件应该怎样打开?
  • /bin/rm: 参数列表过长"的解决办法
  • @拔赤:Web前端开发十日谈
  • [ 渗透测试面试篇 ] 渗透测试面试题大集合(详解)(十)RCE (远程代码/命令执行漏洞)相关面试题
  • [Armbian] 部署Docker版Home Assistent,安装HACS并连接米家设备
  • [BIZ] - 1.金融交易系统特点
  • [BZOJ3757] 苹果树
  • [C++]类和对象【下】