antd可展开表格,点击展开按钮同时展开所有行

Rau*_*aul 8 expandable-table next.js antd

我在我的应用程序中使用 antd design 4.10 版的可扩展表和 Next.js v10.0.4。当我单击+表中的按钮时,它应该只打开选定的行,但我不知道为什么它同时打开所有行。

这是我的表格组件:

<Table
    size="small"
    dataSource={data}
    columns={updateColumns}
    expandable={{
      expandedRowRender: (record) => (
        <p style={{ margin: 0 }}>{record.description}</p>
      ),
      rowExpandable: (record) => record.level !== "3",
      onExpand: (expanded, record) =>
        console.log("onExpand: ", record, expanded),
    }}
  />
Run Code Online (Sandbox Code Playgroud)

与antd design中的文档代码完全相同:https://ant.design/components/table/#components-table-demo-expand

小智 16

key您的数据中的每条记录都需要一个属性。如果没有key属性,可以<Table>使用rowKeyprop在组件上指定它

<Table rowKey="your_data_id" />
Run Code Online (Sandbox Code Playgroud)

  • 对我来说,它必须看起来像这样: ```&lt;Table rowkey={(record) =&gt; record.key} /&gt;``` 并且循环遍历我的数据行并分配一个唯一的 ```key`` `。 (6认同)