简体   繁体   English

如何渲染多个antd表?

[英]how to render multiple antd tables?

I need to render multiple tables instead of one table with many columns.我需要渲染多个表而不是一个包含许多列的表。

Currently the table looks like,目前这张桌子看起来像, 在此处输入图像描述

which renders data into multiple columns.它将数据呈现到多个列中。 I need the data to be rendered into two different tables like,我需要将数据呈现到两个不同的表中,例如,

在此处输入图像描述

The code crashes for some reason while trying to render two tables.代码在尝试渲染两个表时由于某种原因崩溃。

Code:代码:

function App() {
  const data = [
    {
      key: "1",
      rollNo: "16CS21",
      name: "Ronald",
      rank: 2
    },
    {
      key: "2",
      rollNo: "16CS72",
      name: "John",
      rank: 4
    }
  ];
  return (
    <div>
      {data.map((d) => (
        <DetailComponent data={d} />
      ))}
    </div>
  );
}

Table rendering Component:表格渲染组件:

function DetailComponent({ data }) {
      return (
        <div>
          <Table
            dataSource={data}
            pagination={false}
            bordered={false}
            style={{ height: "0px" }}
          >
            <Column title="Roll No" dataIndex="rollNo" key="rollNo" width="100px" />
            <Column title="Name" dataIndex="name" key="name" />
            <Column title="rank" key="rank" dataIndex="rank" />
            <Column
              title="Action"
              key="action"
              render={() => (
                <Space size="middle">
                  <EditTwoTone style={{ fontSize: "18px" }} />
                  <DeleteTwoTone style={{ fontSize: "18px" }} twoToneColor="red" />
                </Space>
              )}
            />
          </Table>
        </div>
      );
    }

CodeSanbox link : https://codesandbox.io/s/tree-data-antd-4-21-0-forked-xxhks9?file=/demo.js CodeSanbox 链接: https ://codesandbox.io/s/tree-data-antd-4-21-0-forked-xxhks9?file=/demo.js

ok i see two issues.好的,我看到两个问题。

  1. unique key prop issue唯一的关键道具问题
  2. remove round brackets like so in map function在地图功能中删除圆括号

data.map((d)=>dataComponent) data.map((d)=>dataComponent)

** Edit ** ** 编辑 **

it seems to me that your table component takes list of objects as data input while you're passing single object.在我看来,您的表格组件在您传递单个对象时将对象列表作为数据输入。 try converting object to array of obejcts like so:尝试将对象转换为对象数组,如下所示:

[].concat(d) [].concat(d)

edit编辑

solution mentioned above seems to fix the issue as shown上面提到的解决方案似乎解决了如图所示的问题在此处输入图像描述

right now both tables are overlaping on each other.现在两个表都相互重叠。 which you can fix.你可以修复它。

make sure to mark the answer if it helped.如果有帮助,请务必标记答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM