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

react antdesign实现表格嵌套表单

在这里插入图片描述
一直使用elementui,后期使用antDesign个人感觉封装的很死没有elementui灵活,也可能是自己不熟吧。做个表格嵌套表单弄半天了。记录下这一过程。官网地址反正我是看半天了。官网地址

主要实现是在每列添加对应的表单控件使用受控组件来实现 <Input value={text} onChange={(e) => handleFieldChange(e, ‘paramName’, index) } 改变当前表格数据来实现数据的改变

const [dataSource, setDataSource] = useState<any[]>([])
// 获取表格行数据const getRowByKey = (key, newData) => {return (newData || dataSource)[key];}// 改变表格数据const handleFieldChange = (e, fileName, key) => {const newData = [...dataSource];const target = getRowByKey(key, newData);if (target) {target[fileName] = e.target.value || e.target.checked;setDataSource(newData);}}// 新增const addData = () => {setDataSource([...dataSource, { paramName: "",paramDesc: "",paramType: "",sampleItem: "",mandatory: true,requiredFlag: 1);};
// 删除const handleRemove = (index) => {const newData = [...dataSource];newData.splice(index, 1);setDataSource(newData);}
const columns: any[] = [{title: '序号',dataIndex: 'key',align: 'center',width: 70,render: (_, __, index) => index + 1},{title: '参数名',align: 'center',dataIndex: 'paramName',minWidth: 100,render: (text, record, index) => {return <Input value={text} onChange={(e) => handleFieldChange(e, 'paramName', index) } />}},{title: '描述',align: 'center',dataIndex: 'paramDesc',minWidth: 100,render: (text, record, index) => {return <Input value={text} onChange={(e) => handleFieldChange(e, 'paramDesc', index) } />}},{title: '数据类型',align: 'center',dataIndex: 'paramType',minWidth: 100,render: (text, record, index) => {return <Input value={text} onChange={(e) => handleFieldChange(e, 'paramType', index) } />}},{title: '示例值',align: 'center',dataIndex: 'sampleItem',minWidth: 100,render: (text, record, index) => {return <Input value={text} onChange={(e) => handleFieldChange(e, 'sampleItem', index) } />}},{title: '校验',align: 'center',dataIndex: 'mandatory',minWidth: 100,render: (text, record, index) => {return <Space><Checkbox checked={text} onChange={(e) => handleFieldChange(e, 'mandatory', index)} /><Button type="link" onClick={() => handleSetRule()}>高级规则</Button>  </Space>}},{title: '操作',align: 'center',minWidth: 100,fixed: 'right',render: (_, record, index) => (<Space><Button type="link" onClick={() => addData()} >追加</Button><Button type="link" danger onClick={() => handleRemove(index)}>删除</Button></Space>  )}]<Tablestyle={{ width: '100%' }}rowKey="key"columns={columns}dataSource={dataSource} // 从表单中获取行数据pagination={false} // 关闭分页(如需分页需额外处理)/>
http://www.dtcms.com/a/565220.html

相关文章:

  • 3D 技术赋能制造企业精准高效装配生产
  • 山东网站建设app江门住房和城乡建设部网站
  • 数据线厂家东莞网站建设wordpress mysql用户名
  • 4G摄像头行业新风向:AI+低功耗+全球化驱动
  • IDEA / DataGrip 连接 SQL Server 提示“驱动程序无法通过 SSL 加密建立安全连接”的解决方法
  • 【11408学习记录】制胜考研英语阅读:拆解2018真题长难句(含三步核心分析法)​
  • # 数学符号参考手册大全
  • Dremio查询加速技术全解析
  • 黄页营销网站视频免费大全免费的网站模板下载
  • Go语言设计模式:观察者模式详解
  • 什么是音频码率?音频码率128kbps怎么设置?
  • 2026版基于python大数据的旅游可视化及推荐系统
  • 企业财务智能体架构解析:从RPA自动化到AI风控协同
  • 北京seo不到首页不扣费厦门seo顾问屈兴东
  • 玩转Rust高级应用 如何进行理解Refutability(可反驳性): 模式是否会匹配失效
  • Excel怎么快速合并当前工作簿下的所有工作表?
  • 网站建设捌金手指花总十六永久链接生成器
  • Nestjs框架: 微服务事件驱动通信与超时处理机制优化基于Event-Based 通信及异常捕获实践
  • html网站建设案例杭州发布官网
  • C语言实现观察者模式
  • JAVA算法练习题day62
  • SAP PP 生产报废单传输接口分享
  • 数据结构——三十八、查找的基本概念(王道408)
  • 深蓝学院 概率图模型
  • Kanass零基础学习,如何快速导入Jira、Mantis数据
  • 漳州网站建设多少钱创业计划书模板
  • linux vscode+cmake+clangd
  • 如何在 Linux 中获取更多信息
  • equals()与hashCode()之间的关系
  • Visual Studio Code 控制台乱码问题