2016-11-02 15:09:54 +08:00
|
|
|
---
|
|
|
|
order: 21
|
|
|
|
title:
|
|
|
|
en-US: Dynamic Settings
|
|
|
|
zh-CN: 动态控制表格属性
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
选择不同配置组合查看效果。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Select different settings to see the result.
|
|
|
|
|
|
|
|
````jsx
|
2016-11-03 10:27:34 +08:00
|
|
|
import { Table, Icon, Switch, Radio, Form } from 'antd';
|
2016-11-02 15:09:54 +08:00
|
|
|
const FormItem = Form.Item;
|
|
|
|
|
|
|
|
const columns = [{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
key: 'name',
|
2016-11-09 20:16:57 +08:00
|
|
|
width: 150,
|
2016-11-02 15:09:54 +08:00
|
|
|
render: text => <a href="#">{text}</a>,
|
|
|
|
}, {
|
|
|
|
title: 'Age',
|
|
|
|
dataIndex: 'age',
|
|
|
|
key: 'age',
|
2016-11-14 14:26:08 +08:00
|
|
|
width: 70,
|
2016-11-02 15:09:54 +08:00
|
|
|
}, {
|
|
|
|
title: 'Address',
|
|
|
|
dataIndex: 'address',
|
|
|
|
key: 'address',
|
|
|
|
}, {
|
|
|
|
title: 'Action',
|
|
|
|
key: 'action',
|
2016-11-14 14:26:08 +08:00
|
|
|
width: 360,
|
2016-11-02 15:09:54 +08:00
|
|
|
render: (text, record) => (
|
|
|
|
<span>
|
|
|
|
<a href="#">Action 一 {record.name}</a>
|
|
|
|
<span className="ant-divider" />
|
|
|
|
<a href="#">Delete</a>
|
|
|
|
<span className="ant-divider" />
|
|
|
|
<a href="#" className="ant-dropdown-link">
|
|
|
|
More actions<Icon type="down" />
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
),
|
|
|
|
}];
|
|
|
|
|
2016-11-09 20:16:57 +08:00
|
|
|
const data = [];
|
|
|
|
for (let i = 1; i <= 10; i++) {
|
|
|
|
data.push({
|
|
|
|
key: i,
|
|
|
|
name: 'John Brown',
|
|
|
|
age: `${i}2`,
|
|
|
|
address: `New York No. ${i} Lake Park`,
|
|
|
|
description: `My name is John Brown, I am ${i}2 years old, living in New York No. ${i} Lake Park.`,
|
|
|
|
});
|
|
|
|
}
|
2016-11-02 15:09:54 +08:00
|
|
|
|
|
|
|
const expandedRowRender = record => <p>{record.description}</p>;
|
|
|
|
const title = () => 'Here is title';
|
|
|
|
const footer = () => 'Here is footer';
|
2016-11-09 20:16:57 +08:00
|
|
|
const scroll = { y: 240 };
|
2016-11-02 15:09:54 +08:00
|
|
|
|
|
|
|
class Demo extends React.Component {
|
|
|
|
state = {
|
2016-11-14 14:26:08 +08:00
|
|
|
bordered: false,
|
2016-11-03 10:27:34 +08:00
|
|
|
loading: false,
|
2016-11-02 15:09:54 +08:00
|
|
|
pagination: true,
|
2016-11-03 10:27:34 +08:00
|
|
|
size: 'default',
|
2016-11-02 15:09:54 +08:00
|
|
|
expandedRowRender,
|
|
|
|
title,
|
|
|
|
footer,
|
2016-11-09 20:16:57 +08:00
|
|
|
rowSelection: {},
|
2016-11-15 20:06:41 +08:00
|
|
|
scroll: undefined,
|
2016-11-02 15:09:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleToggle = (prop) => {
|
2016-11-03 10:27:34 +08:00
|
|
|
return (enable) => {
|
|
|
|
this.setState({ [prop]: enable });
|
2016-11-02 15:09:54 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-03 10:27:34 +08:00
|
|
|
handleSizeChange = (e) => {
|
|
|
|
this.setState({ size: e.target.value });
|
2016-11-02 15:09:54 +08:00
|
|
|
}
|
|
|
|
|
2016-11-03 10:27:34 +08:00
|
|
|
handleExpandChange = (enable) => {
|
|
|
|
this.setState({ expandedRowRender: enable ? expandedRowRender : false });
|
2016-11-02 15:09:54 +08:00
|
|
|
}
|
|
|
|
|
2016-11-03 10:27:34 +08:00
|
|
|
handleTitleChange = (enable) => {
|
|
|
|
this.setState({ title: enable ? title : undefined });
|
2016-11-02 15:09:54 +08:00
|
|
|
}
|
|
|
|
|
2016-11-03 10:27:34 +08:00
|
|
|
handleFooterChange = (enable) => {
|
|
|
|
this.setState({ footer: enable ? footer : undefined });
|
2016-11-02 15:09:54 +08:00
|
|
|
}
|
|
|
|
|
2016-11-09 20:16:57 +08:00
|
|
|
handleRowSelectionChange = (enable) => {
|
|
|
|
this.setState({ rowSelection: enable ? {} : undefined });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleScollChange = (enable) => {
|
|
|
|
this.setState({ scroll: enable ? scroll : undefined });
|
|
|
|
}
|
|
|
|
|
2016-11-02 15:09:54 +08:00
|
|
|
render() {
|
2016-11-03 10:27:34 +08:00
|
|
|
const state = this.state;
|
2016-11-02 15:09:54 +08:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className="components-table-demo-control-bar">
|
|
|
|
<Form inline>
|
2016-11-03 10:27:34 +08:00
|
|
|
<FormItem label="Bordered">
|
|
|
|
<Switch checked={state.bordered} onChange={this.handleToggle('bordered')} />
|
2016-11-02 15:09:54 +08:00
|
|
|
</FormItem>
|
2016-11-03 10:27:34 +08:00
|
|
|
<FormItem label="loading">
|
|
|
|
<Switch checked={state.loading} onChange={this.handleToggle('loading')} />
|
2016-11-02 15:09:54 +08:00
|
|
|
</FormItem>
|
2016-11-03 10:27:34 +08:00
|
|
|
<FormItem label="Pagination">
|
|
|
|
<Switch checked={state.pagination} onChange={this.handleToggle('pagination')} />
|
2016-11-02 15:09:54 +08:00
|
|
|
</FormItem>
|
2016-11-03 10:27:34 +08:00
|
|
|
<FormItem label="Title">
|
2016-11-15 20:06:41 +08:00
|
|
|
<Switch checked={!!state.title} onChange={this.handleTitleChange} />
|
2016-11-02 15:09:54 +08:00
|
|
|
</FormItem>
|
2016-11-03 10:27:34 +08:00
|
|
|
<FormItem label="Footer">
|
2016-11-15 20:06:41 +08:00
|
|
|
<Switch checked={!!state.footer} onChange={this.handleFooterChange} />
|
2016-11-02 15:09:54 +08:00
|
|
|
</FormItem>
|
2016-11-03 10:27:34 +08:00
|
|
|
<FormItem label="Expandable">
|
2016-11-15 20:06:41 +08:00
|
|
|
<Switch checked={!!state.expandedRowRender} onChange={this.handleExpandChange} />
|
2016-11-02 15:09:54 +08:00
|
|
|
</FormItem>
|
2016-11-15 20:06:41 +08:00
|
|
|
<FormItem label="Checkbox">
|
|
|
|
<Switch checked={!!state.rowSelection} onChange={this.handleRowSelectionChange} />
|
2016-11-09 20:16:57 +08:00
|
|
|
</FormItem>
|
|
|
|
<FormItem label="Fixed Header">
|
2016-11-15 20:06:41 +08:00
|
|
|
<Switch checked={!!state.scroll} onChange={this.handleScollChange} />
|
2016-11-09 20:16:57 +08:00
|
|
|
</FormItem>
|
2016-11-03 10:27:34 +08:00
|
|
|
<FormItem label="Size">
|
2016-11-14 14:26:08 +08:00
|
|
|
<Radio.Group size="default" value={state.size} onChange={this.handleSizeChange}>
|
2016-11-03 10:27:34 +08:00
|
|
|
<Radio.Button value="default">Default</Radio.Button>
|
|
|
|
<Radio.Button value="middle">Middle</Radio.Button>
|
|
|
|
<Radio.Button value="small">Small</Radio.Button>
|
|
|
|
</Radio.Group>
|
2016-11-02 15:09:54 +08:00
|
|
|
</FormItem>
|
|
|
|
</Form>
|
|
|
|
</div>
|
|
|
|
<Table {...this.state} columns={columns} dataSource={data} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(<Demo />, mountNode);
|
|
|
|
````
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.components-table-demo-control-bar {
|
|
|
|
margin-bottom: 10px;
|
|
|
|
}
|
2016-11-03 10:27:34 +08:00
|
|
|
.components-table-demo-control-bar .ant-form-item {
|
|
|
|
margin-right: 16px;
|
|
|
|
margin-bottom: 8px;
|
|
|
|
}
|
2016-11-02 15:09:54 +08:00
|
|
|
</style>
|