可以使用 columns 属性中的 render 方法来隐藏表格中的列,同时设置 width 属性为 0,这样就可以隐藏该列且不占据空间。

以下是一个示例代码:

import React from 'react';
import { Table } from 'antd';

const dataSource = [
  {
    key: '1',
    name: 'John',
    age: 32,
    address: 'New York',
  },
  {
    key: '2',
    name: 'Mike',
    age: 28,
    address: 'London',
  },
];

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address',
  },
  {
    title: 'Hidden',
    dataIndex: 'hidden',
    key: 'hidden',
    render: () => null,
    width: 0,
  },
];

const App = () => {
  return <Table dataSource={dataSource} columns={columns} />;
};

export default App;

在上述代码中,我们通过在 columns 数组中添加一个名为 Hidden 的列来隐藏一列,并通过设置 render 方法返回 null 来隐藏列中的内容。此外,我们还设置了 width 属性为 0,以确保该列不占据空间

antd 的table表格如何隐藏一列且不占据空间

原文地址: http://www.cveoy.top/t/topic/id1B 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录