react开发之arco design合并列

前言 最近开发项目过程中,需要用到表格合并行的功能。由于我采用的是arco design组件,所以自带支持的行 […]

前言

最近开发项目过程中,需要用到表格合并行的功能。由于我采用的是arco design组件,所以自带支持的行列合并,我其实需要的列合并列,如下图。

组件代码

import { Button } from '@arco-design/web-react';
import { Space } from '@arco-design/web-react';
import { Table } from '@arco-design/web-react';
const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    render: (col, item, index) => {
      const obj = {
        children: col,
        props: {}
      };

      if (item?.rows?.length) {
        obj.props.colSpan = 4;
      }

      return obj;
    }
  },
  {
    title: 'Salary',
    dataIndex: 'salary',
    render: (col, item, index) => {
      const obj = {
        children: col,
        props: {}
      };

      if (item?.rows?.length) {
        obj.props.colSpan = 0;
      }

      return obj;
    }
  },
  {
    title: 'Detail',
    dataIndex: 'address',
    render: (col, item, index) => {
      const obj = {
        children: col,
        props: {}
      };

      if (item?.rows?.length) {
        obj.props.colSpan = 0;
      }

      return obj;
    }
  },
  {
    title: 'Email',
    dataIndex: 'email',
    render: (col, item, index) => {
      const obj = {
        children: col,
        props: {}
      };

      if (item?.rows?.length) {
        obj.props.colSpan = 0;
      }

      return obj;
    }
  },
  {
    title: '操作',
    dataIndex: 'op',
    width: '160px',
    render: (_, record) => {
      return (
        <Space>
          <Button onClick={() => onEdit(record)} size='small'>
            修改
          </Button>
          <Button onClick={() => onDel(record)} size='small'>
            删除
          </Button>
        </Space>
      );
    }
  }
];

const data = [
  {
    key: '1',
    name: 'Jane Doe',
    salary: 23000,
    address: '32 Park Road, London',
    email: 'jane.doe@example.com',
    rows: [
      {
        key: '1-1',
        name: 'Jane Doe',
        salary: 23000,
        address: '32 Park Road, London',
        email: 'jane.doe@example.com'
      },
      {
        key: '1-2',
        name: 'Jane Doe',
        salary: 23000,
        address: '32 Park Road, London',
        email: 'jane.doe@example.com'
      }
    ]
  },
  {
    key: '2',
    name: 'Jane Doe',
    salary: 23000,
    address: '32 Park Road, London',
    email: 'jane.doe@example.com'
  },
  {
    key: '3',
    name: 'Jane Doe',
    salary: 23000,
    address: '32 Park Road, London',
    email: 'jane.doe@example.com'
  },
  {
    key: '4',
    name: 'Jane Doe',
    salary: 23000,
    address: '32 Park Road, London',
    email: 'jane.doe@example.com'
  },
  {
    key: '5',
    name: 'Jane Doe',
    salary: 23000,
    address: '32 Park Road, London',
    email: 'jane.doe@example.com',
    rows: [
      {
        key: '5-1',
        name: 'Jane Doe',
        salary: 23000,
        address: '32 Park Road, London',
        email: 'jane.doe@example.com'
      },
      {
        key: '5-2',
        name: 'Jane Doe',
        salary: 23000,
        address: '32 Park Road, London',
        email: 'jane.doe@example.com'
      }
    ]
  },
  {
    key: '6',
    name: 'Jane Doe',
    salary: 23000,
    address: '32 Park Road, London',
    email: 'jane.doe@example.com'
  },
  {
    key: '7',
    name: 'Jane Doe',
    salary: 23000,
    address: '32 Park Road, London',
    email: 'jane.doe@example.com'
  },
  {
    key: '8',
    name: 'Jane Doe',
    salary: 23000,
    address: '32 Park Road, London',
    email: 'jane.doe@example.com'
  },
];

const TreeTable = () => {
  return <Table border borderCell hover columns={columns} data={data} pagination={false} />;
};

export default TreeTable;

核心说明:

// 只要有子节点就合并整列
if (item?.rows?.length) {
   obj.props.colSpan = 4;
}

 

 

版权声明
文章标题:react开发之arco design合并列
文章链接:https://blog.chiyuba.com/qianduanjishu/590.html
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,转载或引用请注明出处。
温馨提示:本文最后更新于 2025年7月12日,部分内容可能存在时效性,请注意甄别。

相关推荐

更多教程
Qt QTableView setData的坑 UI相关 Qt QTableView setData的坑

前言 最近在使用QTableView的时...

25 浏览
ssycms模板开发之模板常用的文章列表调用代码 UI相关 ssycms模板开发之模板常用的文章列表调用代码

最新文章 {tag:article id...

38 浏览
Qt 删除QGridLayout布局 UI相关 Qt 删除QGridLayout布局

前言 最近在使用QGridLayout动...

31 浏览

评论