分组表格antd+ react +ts

server/2025/2/1 1:32:52/
import React from "react";
import { Table, Tag } from "antd";
import styles from "./index.less";
import GroupTag from "../Tag";
const GroupTable = () => {const columns = [{title: "姓名",dataIndex: "name",key: "name",render: (text, record) => customRowRender(record, <a>{text}</a>),/* 合并单元格列 */onCell: (record) => {if (record.isGroupTag) {return {colSpan: 5,};}},},{title: "性别",dataIndex: "gender",key: "gender",render: (text) => text && (text === 0 ? "男" : "女"),/* 合并单元格列 */onCell: (record) => {if (record.isGroupTag) {return {colSpan: 0,};}},},{title: "年龄",dataIndex: "age",key: "age",/* 合并单元格列 */onCell: (record) => {if (record.isGroupTag) {return {colSpan: 0,};}},},{title: "地址",dataIndex: "address",key: "address",/* 合并单元格列 */onCell: (record) => {if (record.isGroupTag) {return {colSpan: 0,};}},},{title: "出生日期",key: "birthday",dataIndex: "birthday",/* 合并单元格列 */onCell: (record) => {if (record.isGroupTag) {return {colSpan: 0,};}},},];const data = [{key: "1",title: "家人",tagColor: "rgba(10, 196, 72, 1)",data: [{key: "1",name: "张三",gender: 0,age: 32,address: "浙江省杭州市余杭区五常街道幸福小区3幢1单元202室",birthday: "1991-03-04",},{key: "2",name: "李四",gender: 1,age: 19,address: "浙江省杭州市余杭区五常街道幸福小区5幢2单元301室",birthday: "2004-01-26",},{key: "3",name: "王五",gender: 0,age: 26,address: "浙江省杭州市余杭区五常街道幸福小区7幢3单元503室",birthday: "1997-10-17",},],},{key: "2",title: "朋友",tagColor: "rgba(34, 139, 34, 1)",data: [{key: "4",name: "张三",gender: 0,age: 32,address: "浙江省杭州市余杭区五常街道幸福小区3幢1单元202室",birthday: "1991-03-04",},{key: "5",name: "李四",gender: 1,age: 19,address: "浙江省杭州市余杭区五常街道幸福小区5幢2单元301室",birthday: "2004-01-26",},{key: "6",name: "王五",gender: 0,age: 26,address: "浙江省杭州市余杭区五常街道幸福小区7幢3单元503室",birthday: "1997-10-17",},],},{key: "3",title: "同事",tagColor: "rgba(255, 173, 10, 1)",data: [{key: "7",name: "张三",gender: 0,age: 32,address: "浙江省杭州市余杭区五常街道幸福小区3幢1单元202室",birthday: "1991-03-04",},{key: "8",name: "李四",gender: 1,age: 19,address: "浙江省杭州市余杭区五常街道幸福小区5幢2单元301室",birthday: "2004-01-26",},{key: "9",name: "王五",gender: 0,age: 26,address: "浙江省杭州市余杭区五常街道幸福小区7幢3单元503室",birthday: "1997-10-17",},],},] as any;const tableData = data.flatMap((group) => [{key: `${group.key}-tag`,groupTag: group.title,tagColor: group.tagColor,isGroupTag: true,},...group.data.map((item) => ({ ...item, group })),]);const customRowRender = (record, children) => {console.log(record, "???");if (record.isGroupTag) {return {children: (<td colSpan={columns.length}><GroupTag color={record.tagColor} text={record.groupTag} />{/* <Tag color={record.tagColor}>{record.groupTag}</Tag> */}</td>),props: {colSpan: columns.length,},};}return children;};return (<div><Tablecolumns={columns}dataSource={tableData}pagination={false}rowKey={(record) => record.key}rowClassName={(record) => (record.isGroupTag ? styles.groupTagRow : "")}/></div>);
};export default GroupTable;
.groupTagRow {:global {td.ant-table-cell {padding:12px 0px 0px 0px  !important;border: unset !important;}}
}

效果
在这里插入图片描述


http://www.ppmy.cn/server/163932.html

相关文章

Sentinel 控制台集成 Nacos 实现规则配置双向同步和持久化存储(提供改造后源码)

目录 一、前言二、Sentinel 控制台规则推送实现原理三、Sentinel控制台源码改造前置准备工作3.1、本文使用各组件版本3.2、下载Sentinel控制台源码3.3、启动Sentinel控制台3.4、应用服务实现 Sentinel 客户端动态获取 Nacos 规则配置3.4.1、添加sentinel集成nacos包 3.4.2、Nac…

使用iis服务器模拟本地资源服务器unityaddressables热更新出错记录

editor中设置了using exculexing 模拟远程加载addressable可以实现资源热更新&#xff0c;build后的软件却没有成功。 iis服务器中mime中需要设置bundle的文件扩展名&#xff0c;时editor成功&#xff0c;build后失败 原因没有设置hash的扩展名&#xff0c;设置后editor和buil…

volatile

文章目录 ResortSeqDemo.javaSingletonDemo.javaSingletonDemo2.javaVolatileDemo.java ResortSeqDemo.java package com.xd.thread;public class ResortSeqDemo {volatile int a0;boolean flagfalse;/*多线程下flagtrue可能先执行&#xff0c;还没走到a1就被挂起其他线程进入…

Redis内部数据结构--跳表详解

跳表 1. 什么是跳表--skiplist2. skiplist的效率如何保证3. 跳表的实现4. 跳表与平衡搜索树和哈希表的对比 1. 什么是跳表–skiplist skiplist本质上也是一种查找结构&#xff0c;用于解决算法中的查找问题&#xff0c;跟平衡搜索树和哈希表的价值是一样的&#xff0c;可以作为…

我的毕设之路:(2)系统类型的论文写法

一般先进行毕设的设计与实现&#xff0c;再在现成毕设基础上进行描述形成文档&#xff0c;那么论文也就成形了。 1 需求分析&#xff1a;毕业设计根据开题报告和要求进行需求分析和功能确定&#xff0c;区分贴合主题的主要功能和拓展功能能&#xff0c;删除偏离无关紧要的功能…

一文讲解JVM中的G1垃圾收集器

接上一篇博文&#xff0c;这篇博文讲下JVM中的G1垃圾收集器 G1在JDK1.7时引入&#xff0c;在JDK9时取代了CMS成为默认的垃圾收集器&#xff1b; G1把Java堆划分为多个大小相等的独立区域Region&#xff0c;每个区域都可以扮演新生代&#xff08;Eden和Survivor&#xff09;或老…

mysql_store_result的概念和使用案例

mysql_store_result() 是 MySQL C API 中的一个函数&#xff0c;用于检索一个完整的结果集到一个客户端。当执行一个查询&#xff08;通常是 SELECT 查询&#xff09;并希望处理所有返回的数据时&#xff0c;可以使用此函数。 概念 mysql_store_result() 函数的原型如下&…

UE求职Demo开发日志#14 把特效换成通过GC应用,同时完善每段的特效,增加显示物品信息的UI

1 把之前的特效在GC里实现 在DefaultGame.ini里添加这个指定查找路径&#xff1a; [/Script/GameplayAbilities.AbilitySystemGlobals] GameplayCueNotifyPaths"/Game/GAS/GC" 添加标签&#xff1a; 在路径下创建一个GC蓝图&#xff0c;并设置好标签&#xff1a; 重…