antd table column隐藏
时间: 2023-10-02 09:07:52 浏览: 61
若想隐藏Ant Design中的Table组件的某一列,可以在该列的配置项中设置 `hidden` 属性为 `true`。
例如:
```jsx
<Table dataSource={dataSource}>
<Column title="Name" dataIndex="name" key="name" />
<Column title="Age" dataIndex="age" key="age" />
<Column title="Address" dataIndex="address" key="address" hidden={true} />
</Table>
```
这样就会将表格中的“Address”列隐藏起来。
相关问题
antd Table隐藏列
要隐藏Antd Table中的列,您可以使用`columns`属性来指定要显示的列。您可以将要隐藏的列从该数组中删除,然后将新数组传递给`columns`属性。例如,如果您要隐藏名称为“age”的列,可以按如下方式处理:
```jsx
import React from 'react';
import { Table } from 'antd';
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
},
{
title: 'Age',
dataIndex: 'age',
key: 'age',
},
{
title: 'Address',
dataIndex: 'address',
key: 'address',
},
];
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',
},
];
const App = () => {
const newColumns = columns.filter(column => column.key !== 'age');
return (
<Table columns={newColumns} dataSource={data} />
);
};
export default App;
```
在上面的代码中,我们使用`filter()`方法来删除`columns`数组中的“age”列,并将新数组传递给`columns`属性。这将导致只显示“Name”和“Address”列。
antd table中 column中字段是list数组
如果antd table中column中的字段是一个list数组,你可以使用render函数来将其展示出来。在render函数中,你可以使用map方法对数组进行遍历,然后将每个元素展示出来。
例如:
```jsx
const dataSource = [
{
key: '1',
name: 'John Brown',
hobbies: ['reading', 'swimming', 'hiking'],
},
{
key: '2',
name: 'Jim Green',
hobbies: ['cooking', 'running', 'dancing'],
},
];
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
},
{
title: 'Hobbies',
dataIndex: 'hobbies',
key: 'hobbies',
render: hobbies => (
<>
{hobbies.map(hobby => (
<Tag key={hobby}>{hobby}</Tag>
))}
</>
),
},
];
<Table dataSource={dataSource} columns={columns} />;
```
以上代码中,我们将数据源dataSource中的每一项都包含了一个名为"hobbies"的数组。在columns中,我们使用了render函数来将"hobbies"数组中的每个元素展示成一个标签(Tag)。通过这样的方式,我们就可以将一个list数组展示在antd table中了。