简体   繁体   English

React Ant 设计虽然数据可见,但表格不可见

[英]React Ant design Table is not visible although data is visible

I am trying to create a table from ant design react I have copied an example but When I am trying to run it the output is not as expected.我正在尝试从 ant 设计反应创建一个表,我复制了一个示例,但是当我尝试运行它时,output 并不像预期的那样。 Although I am using the same code can someone tell me what is the problem尽管我使用的是相同的代码,但有人可以告诉我问题出在哪里

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    filters: [
      {
        text: 'Joe',
        value: 'Joe',
      },
      {
        text: 'Category 1',
        value: 'Category 1',
        children: [
          {
            text: 'Yellow',
            value: 'Yellow',
          },
          {
            text: 'Pink',
            value: 'Pink',
          },
        ],
      },
      {
        text: 'Category 2',
        value: 'Category 2',
        children: [
          {
            text: 'Green',
            value: 'Green',
          },
          {
            text: 'Black',
            value: 'Black',
          },
        ],
      },
    ],
    filterMode: 'tree',
    filterSearch: true,
    onFilter: (value, record) => record.name.includes(value),
    width: '30%',
  },
  {
    title: 'Age',
    dataIndex: 'age',
    sorter: (a, b) => a.age - b.age,
  },
  {
    title: 'Address',
    dataIndex: 'address',
    filters: [
      {
        text: 'London',
        value: 'London',
      },
      {
        text: 'New York',
        value: 'New York',
      },
    ],
    onFilter: (value, record) => record.address.startsWith(value),
    filterSearch: true,
    width: '40%',
  },
];
const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park',
  },
  {
    key: '2',
    name: 'Jim Green',
    age: 42,
    address: 'London No. 1 Lake Park',
  },
  {
    key: '3',
    name: 'Joe Black',
    age: 32,
    address: 'Sidney No. 1 Lake Park',
  },
  {
    key: '4',
    name: 'Jim Red',
    age: 32,
    address: 'London No. 2 Lake Park',
  },
];

const onChange = (pagination, filters, sorter, extra) => {
  console.log('params', pagination, filters, sorter, extra);
};

const DataTable = () =>{
  return(
    <div className='data-table'>

<Table columns={columns} dataSource={data} onChange={onChange} bordered/>
    </div>
  );
};



export default DataTable;

The table was supposed to be: enter image description here该表应该是:在此处输入图像描述

But the output is: enter image description here但是 output 是:在此处输入图像描述

I was used the same code entered the same components I am unable to understand what the problem is.我使用相同的代码输入相同的组件我无法理解问题所在。

It seems that the antd styles were missing.好像缺少 antd styles。 In order to load the styles correctly, add the following line to your index.js file.为了正确加载 styles,将以下行添加到您的 index.js 文件中。

import "antd/dist/antd.css";

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

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