2016-03-31 09:40:55 +08:00
|
|
|
---
|
2016-05-21 18:08:09 +08:00
|
|
|
order: 15
|
2016-08-15 07:54:01 +08:00
|
|
|
title:
|
|
|
|
en-US: Tree data
|
|
|
|
zh-CN: 树形数据展示
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-12-25 15:46:15 +08:00
|
|
|
|
2016-08-15 07:54:01 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2015-12-25 15:46:15 +08:00
|
|
|
表格支持树形数据的展示,可以通过设置 `indentSize` 以控制每一层的缩进宽度。
|
|
|
|
|
2016-03-16 16:39:53 +08:00
|
|
|
> 注:暂不支持父子数据递归关联选择。
|
|
|
|
|
2016-08-15 08:07:03 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
Display tree structure data in Table, control the indent width by setting `indentSize`.
|
|
|
|
|
|
|
|
> Note, no support for recursive selection of tree structure data table yet.
|
|
|
|
|
2015-12-25 15:46:15 +08:00
|
|
|
````jsx
|
|
|
|
import { Table } from 'antd';
|
|
|
|
|
|
|
|
const columns = [{
|
2016-10-02 08:35:06 +08:00
|
|
|
title: 'Name',
|
2015-12-25 15:46:15 +08:00
|
|
|
dataIndex: 'name',
|
|
|
|
key: 'name',
|
|
|
|
width: '40%',
|
|
|
|
}, {
|
2016-10-02 08:35:06 +08:00
|
|
|
title: 'Age',
|
2015-12-25 15:46:15 +08:00
|
|
|
dataIndex: 'age',
|
|
|
|
key: 'age',
|
|
|
|
width: '30%',
|
|
|
|
}, {
|
2016-10-02 08:35:06 +08:00
|
|
|
title: 'Address',
|
2015-12-25 15:46:15 +08:00
|
|
|
dataIndex: 'address',
|
|
|
|
key: 'address',
|
|
|
|
width: '30%',
|
|
|
|
}];
|
|
|
|
|
|
|
|
const data = [{
|
|
|
|
key: 1,
|
2016-10-02 08:35:06 +08:00
|
|
|
name: 'John Brown sr.',
|
|
|
|
age: 60,
|
|
|
|
address: 'New York No. 1 Lake Park',
|
2015-12-25 15:46:15 +08:00
|
|
|
children: [{
|
|
|
|
key: 11,
|
2016-10-02 08:35:06 +08:00
|
|
|
name: 'John Brown',
|
|
|
|
age: 42,
|
|
|
|
address: 'New York No. 2 Lake Park',
|
2015-12-25 15:46:15 +08:00
|
|
|
}, {
|
|
|
|
key: 12,
|
2016-10-02 08:35:06 +08:00
|
|
|
name: 'John Brown jr.',
|
|
|
|
age: 30,
|
|
|
|
address: 'New York No. 3 Lake Park',
|
2015-12-25 15:46:15 +08:00
|
|
|
children: [{
|
|
|
|
key: 121,
|
2016-10-02 08:35:06 +08:00
|
|
|
name: 'Jimmy Brown',
|
|
|
|
age: 16,
|
|
|
|
address: 'New York No. 3 Lake Park',
|
2015-12-25 15:46:15 +08:00
|
|
|
}],
|
|
|
|
}, {
|
|
|
|
key: 13,
|
2016-10-02 08:35:06 +08:00
|
|
|
name: 'Jim Green sr.',
|
|
|
|
age: 72,
|
|
|
|
address: 'London No. 1 Lake Park',
|
2015-12-25 15:46:15 +08:00
|
|
|
children: [{
|
|
|
|
key: 131,
|
2016-10-02 08:35:06 +08:00
|
|
|
name: 'Jim Green',
|
|
|
|
age: 42,
|
|
|
|
address: 'London No. 2 Lake Park',
|
2015-12-25 15:46:15 +08:00
|
|
|
children: [{
|
|
|
|
key: 1311,
|
2016-10-02 08:35:06 +08:00
|
|
|
name: 'Jim Green jr.',
|
|
|
|
age: 25,
|
|
|
|
address: 'London No. 3 Lake Park',
|
2015-12-25 15:46:15 +08:00
|
|
|
}, {
|
|
|
|
key: 1312,
|
2016-10-02 08:35:06 +08:00
|
|
|
name: 'Jimmy Green sr.',
|
|
|
|
age: 18,
|
|
|
|
address: 'London No. 4 Lake Park',
|
2015-12-25 15:46:15 +08:00
|
|
|
}],
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
}, {
|
|
|
|
key: 2,
|
2016-10-02 08:35:06 +08:00
|
|
|
name: 'Joe Black',
|
2015-12-25 15:46:15 +08:00
|
|
|
age: 32,
|
2016-10-02 08:35:06 +08:00
|
|
|
address: 'Sidney No. 1 Lake Park',
|
2015-12-25 15:46:15 +08:00
|
|
|
}];
|
|
|
|
|
2016-10-02 08:35:06 +08:00
|
|
|
// rowSelection objects indicates the need for row selection
|
2016-03-16 16:39:53 +08:00
|
|
|
const rowSelection = {
|
|
|
|
onChange(selectedRowKeys, selectedRows) {
|
|
|
|
console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
|
|
|
|
},
|
|
|
|
onSelect(record, selected, selectedRows) {
|
|
|
|
console.log(record, selected, selectedRows);
|
|
|
|
},
|
|
|
|
onSelectAll(selected, selectedRows, changeRows) {
|
|
|
|
console.log(selected, selectedRows, changeRows);
|
2016-05-03 14:15:29 +08:00
|
|
|
},
|
2016-03-16 16:39:53 +08:00
|
|
|
};
|
|
|
|
|
2015-12-25 15:46:15 +08:00
|
|
|
ReactDOM.render(
|
2016-03-16 16:39:53 +08:00
|
|
|
<Table columns={columns} rowSelection={rowSelection} dataSource={data} />,
|
2015-12-29 12:08:58 +08:00
|
|
|
mountNode
|
2015-12-25 15:46:15 +08:00
|
|
|
);
|
|
|
|
````
|