2016-11-22 10:11:12 +08:00
|
|
|
|
---
|
|
|
|
|
order: 1
|
|
|
|
|
title:
|
|
|
|
|
en-US: JSX style API
|
|
|
|
|
zh-CN: JSX 风格的 API
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
|
|
使用 JSX 风格的 API(2.5.0 以后引入)
|
|
|
|
|
|
2017-01-12 00:03:35 +08:00
|
|
|
|
> 这个只是一个描述 `columns` 的语法糖,所以你不能用其他组件去包裹 `Column` 和 `ColumnGroup`。
|
2017-01-11 19:52:43 +08:00
|
|
|
|
|
2016-11-22 10:11:12 +08:00
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
|
|
Using JSX style API (introduced in 2.5.0)
|
|
|
|
|
|
2018-04-23 21:57:43 +08:00
|
|
|
|
> Since this is just a syntax sugar for the prop `columns`, you can't compose `Column` and `ColumnGroup` with other Components.
|
2017-01-11 19:52:43 +08:00
|
|
|
|
|
2017-02-13 10:55:53 +08:00
|
|
|
|
````jsx
|
2018-08-18 12:48:56 +08:00
|
|
|
|
import { Table, Divider, Tag } from 'antd';
|
2016-11-22 10:11:12 +08:00
|
|
|
|
|
|
|
|
|
const { Column, ColumnGroup } = Table;
|
|
|
|
|
|
|
|
|
|
const data = [{
|
|
|
|
|
key: '1',
|
|
|
|
|
firstName: 'John',
|
|
|
|
|
lastName: 'Brown',
|
|
|
|
|
age: 32,
|
|
|
|
|
address: 'New York No. 1 Lake Park',
|
2018-08-18 12:48:56 +08:00
|
|
|
|
tags: ['nice', 'developer'],
|
2016-11-22 10:11:12 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: '2',
|
|
|
|
|
firstName: 'Jim',
|
|
|
|
|
lastName: 'Green',
|
|
|
|
|
age: 42,
|
|
|
|
|
address: 'London No. 1 Lake Park',
|
2018-08-18 12:48:56 +08:00
|
|
|
|
tags: ['loser'],
|
2016-11-22 10:11:12 +08:00
|
|
|
|
}, {
|
|
|
|
|
key: '3',
|
|
|
|
|
firstName: 'Joe',
|
|
|
|
|
lastName: 'Black',
|
|
|
|
|
age: 32,
|
|
|
|
|
address: 'Sidney No. 1 Lake Park',
|
2018-08-18 12:48:56 +08:00
|
|
|
|
tags: ['cool', 'teacher'],
|
2016-11-22 10:11:12 +08:00
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
ReactDOM.render(
|
2017-01-10 14:09:19 +08:00
|
|
|
|
<Table dataSource={data}>
|
2016-11-22 10:11:12 +08:00
|
|
|
|
<ColumnGroup title="Name">
|
|
|
|
|
<Column
|
|
|
|
|
title="First Name"
|
|
|
|
|
dataIndex="firstName"
|
|
|
|
|
key="firstName"
|
|
|
|
|
/>
|
|
|
|
|
<Column
|
|
|
|
|
title="Last Name"
|
|
|
|
|
dataIndex="lastName"
|
|
|
|
|
key="lastName"
|
|
|
|
|
/>
|
|
|
|
|
</ColumnGroup>
|
|
|
|
|
<Column
|
|
|
|
|
title="Age"
|
|
|
|
|
dataIndex="age"
|
|
|
|
|
key="age"
|
|
|
|
|
/>
|
|
|
|
|
<Column
|
|
|
|
|
title="Address"
|
|
|
|
|
dataIndex="address"
|
|
|
|
|
key="address"
|
|
|
|
|
/>
|
2018-08-18 12:48:56 +08:00
|
|
|
|
<Column
|
|
|
|
|
title="Tags"
|
|
|
|
|
dataIndex="tags"
|
|
|
|
|
key="tags"
|
|
|
|
|
render={tags => (
|
|
|
|
|
<span>
|
|
|
|
|
{tags.map(tag => <Tag color="blue" key={tag}>{tag}</Tag>)}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2016-11-22 10:11:12 +08:00
|
|
|
|
<Column
|
|
|
|
|
title="Action"
|
|
|
|
|
key="action"
|
|
|
|
|
render={(text, record) => (
|
|
|
|
|
<span>
|
2018-08-18 12:48:56 +08:00
|
|
|
|
<a href="javascript:;">Invite {record.lastName}</a>
|
2017-08-19 12:39:11 +08:00
|
|
|
|
<Divider type="vertical" />
|
2018-04-11 15:15:24 +08:00
|
|
|
|
<a href="javascript:;">Delete</a>
|
2016-11-22 10:11:12 +08:00
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2018-06-27 15:55:04 +08:00
|
|
|
|
</Table>,
|
2018-11-28 15:00:03 +08:00
|
|
|
|
mountNode
|
|
|
|
|
);
|
2016-11-22 10:11:12 +08:00
|
|
|
|
````
|