【问题标题】:Ant design Table configuration蚂蚁设计表配置
【发布时间】:2020-05-11 03:00:41
【问题描述】:

我正在使用 Ant Design Table 组件,但无法找出扩展属性与根表相比的不同列结构。

现在,如果您运行以下代码,您会发现父列结构和子列结构,或者可能会说扩展表结构是相同的。

我想知道如何使父子列结构不同。

注意:我不能使用“expandedRowRender”属性,因为我们不想显示每一行的扩展属性。

Structer shown in this image

      NAME(Column Name)    Age              Address
      Mick                 1                New York No. 1 Lake Park
+     John Brown sr.       2               New York No. 2 Lake Park
           Name            Age              Address
           John Brown      1                New York No. 1 Lake Park
           Any Name        2                New York No. 2 Lake Park
      Amey                 3                New York No. 3 Lake Park

您可以看到 1 级和 2 级列结构是相同的只有第二行具有该属性。

如果我不能以适当的方式提出问题,请向老师道歉。


import React from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
import { Table } from 'antd';

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
    width: '12%',
  },
  {
    title: 'Address',
    dataIndex: 'address',
    width: '30%',
    key: 'address',
  }
];

const data = [
  {
    key: 1,
    name: 'John Brown sr.',
    age: 60,
    address: 'New York No. 1 Lake Park',
    children: [
      {
        key: 11,
        aa: 11111,
        bb: 22222,
        name: 'John Brown',
        age: 42,
        address: 'New York No. 2 Lake Park',
      },
      {
        key: 12,
        name: 'John Brown jr.',
        age: 30,
        address: 'New York No. 3 Lake Park',
        children: [
          {
            key: 121,
            name: 'Jimmy Brown',
            age: 16,
            address: 'New York No. 3 Lake Park',
          },
        ],
      },
      {
        key: 13,
        name: 'Jim Green sr.',
        age: 72,
        address: 'London No. 1 Lake Park',
        children: [
          {
            key: 131,
            name: 'Jim Green',
            age: 42,
            address: 'London No. 2 Lake Park',
            children: [
              {
                key: 1311,
                name: 'Jim Green jr.',
                age: 25,
                address: 'London No. 3 Lake Park',
              },
              {
                key: 1312,
                name: 'Jimmy Green sr.',
                age: 18,
                address: 'London No. 4 Lake Park',
              },
            ],
          },
        ],
      },
    ],
  },
  {
    key: 2,
    name: 'Joe Black',
    age: 32,
    address: 'Sidney No. 1 Lake Park',
  },
];

ReactDOM.render(
  <Table columns={columns} dataSource={data} />,
  document.getElementById('container'),
);

【问题讨论】:

  • 你的问题不清楚,这是什么意思column structure different你应该在你的问题中显示不同的意思
  • 谢谢@Dennis vash 我将编辑一个问题以更清晰。

标签: javascript reactjs antd ant-design-pro


【解决方案1】:

注意:我不能使用“expandedRowRender”属性,因为我们不想显示每一行的扩展属性。

我不得不做类似的事情。所以我使用了expandedRowRender 和不同的行的类名(基于他们是否有扩展属性(item.children))并使用css属性来隐藏没有孩子的行上的展开按钮。

.class_name_to_hide_expand .ant-table-row-expand-icon-cell .ant-table-row-expand-icon{
  opacity: 0;
  pointer-events: none
}

【讨论】:

  • 感谢您告诉我这种方法,我会尽力让您知道。谢谢。
  • 很高兴能帮到你☺️
猜你喜欢
  • 2021-12-12
  • 1970-01-01
  • 2019-04-06
  • 2020-07-12
  • 1970-01-01
  • 2020-09-03
  • 1970-01-01
  • 1970-01-01
  • 2020-08-21
相关资源
最近更新 更多