2016-11-02 15:09:54 +08:00
|
|
|
---
|
2019-09-03 18:47:17 +08:00
|
|
|
order: 100
|
2016-11-02 15:09:54 +08:00
|
|
|
title:
|
|
|
|
en-US: Dynamic Settings
|
|
|
|
zh-CN: 动态控制表格属性
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
选择不同配置组合查看效果。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Select different settings to see the result.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2019-08-13 14:07:17 +08:00
|
|
|
import { Table, Switch, Radio, Form, Divider } from 'antd';
|
|
|
|
import { Down } from '@ant-design/icons';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
key: 'name',
|
2019-08-14 19:36:59 +08:00
|
|
|
render: text => <a>{text}</a>,
|
2019-05-07 14:57:32 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Age',
|
|
|
|
dataIndex: 'age',
|
|
|
|
key: 'age',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Address',
|
|
|
|
dataIndex: 'address',
|
|
|
|
key: 'address',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Action',
|
|
|
|
key: 'action',
|
|
|
|
render: (text, record) => (
|
|
|
|
<span>
|
2019-08-14 19:36:59 +08:00
|
|
|
<a>Action 一 {record.name}</a>
|
2019-05-07 14:57:32 +08:00
|
|
|
<Divider type="vertical" />
|
2019-08-14 19:36:59 +08:00
|
|
|
<a>Delete</a>
|
2019-05-07 14:57:32 +08:00
|
|
|
<Divider type="vertical" />
|
2019-08-14 19:36:59 +08:00
|
|
|
<a className="ant-dropdown-link">
|
2019-08-13 14:07:17 +08:00
|
|
|
More actions <Down />
|
2019-05-07 14:57:32 +08:00
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
2016-11-02 15:09:54 +08:00
|
|
|
|
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
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
const expandable = { expandedRowRender: record => <p>{record.description}</p> };
|
2016-11-02 15:09:54 +08:00
|
|
|
const title = () => 'Here is title';
|
2016-12-27 17:47:27 +08:00
|
|
|
const showHeader = true;
|
2016-11-02 15:09:54 +08:00
|
|
|
const footer = () => 'Here is footer';
|
2018-03-15 14:26:28 +08:00
|
|
|
const pagination = { position: 'bottom' };
|
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,
|
2018-03-02 14:12:30 +08:00
|
|
|
pagination,
|
2016-11-03 10:27:34 +08:00
|
|
|
size: 'default',
|
2019-11-15 14:35:25 +08:00
|
|
|
expandable,
|
2018-03-15 14:26:28 +08:00
|
|
|
title: undefined,
|
2016-12-27 17:47:27 +08:00
|
|
|
showHeader,
|
2016-11-02 15:09:54 +08:00
|
|
|
footer,
|
2016-11-09 20:16:57 +08:00
|
|
|
rowSelection: {},
|
2016-11-15 20:06:41 +08:00
|
|
|
scroll: undefined,
|
2018-09-17 14:36:26 +08:00
|
|
|
hasData: true,
|
2019-09-04 18:12:57 +08:00
|
|
|
tableLayout: undefined,
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2016-11-02 15:09:54 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleToggle = prop => enable => {
|
2018-11-28 15:00:03 +08:00
|
|
|
this.setState({ [prop]: enable });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2016-11-02 15:09:54 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleSizeChange = e => {
|
2016-11-03 10:27:34 +08:00
|
|
|
this.setState({ size: e.target.value });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2016-11-02 15:09:54 +08:00
|
|
|
|
2019-09-04 18:12:57 +08:00
|
|
|
handleTableLayoutChange = e => {
|
|
|
|
this.setState({ tableLayout: e.target.value });
|
|
|
|
};
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleExpandChange = enable => {
|
2019-11-15 14:35:25 +08:00
|
|
|
this.setState({ expandable: enable ? expandable : undefined });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2016-11-02 15:09:54 +08:00
|
|
|
|
2019-09-04 18:12:57 +08:00
|
|
|
handleEllipsisChange = enable => {
|
|
|
|
this.setState({ ellipsis: enable });
|
|
|
|
};
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleTitleChange = enable => {
|
2016-11-03 10:27:34 +08:00
|
|
|
this.setState({ title: enable ? title : undefined });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2016-11-02 15:09:54 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleHeaderChange = enable => {
|
2016-12-27 17:47:27 +08:00
|
|
|
this.setState({ showHeader: enable ? showHeader : false });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2016-12-27 17:47:27 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleFooterChange = enable => {
|
2016-11-03 10:27:34 +08:00
|
|
|
this.setState({ footer: enable ? footer : undefined });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2016-11-02 15:09:54 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleRowSelectionChange = enable => {
|
2016-11-09 20:16:57 +08:00
|
|
|
this.setState({ rowSelection: enable ? {} : undefined });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2016-11-09 20:16:57 +08:00
|
|
|
|
2019-11-15 14:35:25 +08:00
|
|
|
handleYScrollChange = enable => {
|
|
|
|
this.setState({ yScroll: enable });
|
|
|
|
};
|
|
|
|
|
|
|
|
handleXScrollChange = e => {
|
|
|
|
this.setState({ xScroll: e.target.value });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2016-11-09 20:16:57 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleDataChange = hasData => {
|
2018-09-17 14:36:26 +08:00
|
|
|
this.setState({ hasData });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-09-17 14:36:26 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handlePaginationChange = e => {
|
2018-03-15 14:26:28 +08:00
|
|
|
const { value } = e.target;
|
|
|
|
this.setState({
|
|
|
|
pagination: value === 'none' ? false : { position: value },
|
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-03-02 12:35:25 +08:00
|
|
|
|
2016-11-02 15:09:54 +08:00
|
|
|
render() {
|
2019-11-15 14:35:25 +08:00
|
|
|
const { xScroll, yScroll, ...state } = this.state;
|
|
|
|
|
|
|
|
const scroll = {};
|
|
|
|
if (yScroll) {
|
|
|
|
scroll.y = 240;
|
|
|
|
}
|
|
|
|
if (xScroll) {
|
|
|
|
scroll.x = '100vw';
|
|
|
|
}
|
|
|
|
|
|
|
|
const tableColumns = columns.map(item => ({ ...item, ellipsis: state.ellipsis }));
|
|
|
|
if (xScroll === 'fixed') {
|
|
|
|
tableColumns[0].fixed = true;
|
|
|
|
tableColumns[tableColumns.length - 1].fixed = 'right';
|
|
|
|
}
|
|
|
|
|
2016-11-02 15:09:54 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2019-09-04 18:12:57 +08:00
|
|
|
<Form
|
|
|
|
layout="inline"
|
|
|
|
className="components-table-demo-control-bar"
|
|
|
|
style={{ marginBottom: 16 }}
|
|
|
|
>
|
|
|
|
<Form.Item label="Bordered">
|
|
|
|
<Switch checked={state.bordered} onChange={this.handleToggle('bordered')} />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="loading">
|
|
|
|
<Switch checked={state.loading} onChange={this.handleToggle('loading')} />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Title">
|
|
|
|
<Switch checked={!!state.title} onChange={this.handleTitleChange} />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Column Header">
|
|
|
|
<Switch checked={!!state.showHeader} onChange={this.handleHeaderChange} />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Footer">
|
|
|
|
<Switch checked={!!state.footer} onChange={this.handleFooterChange} />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Expandable">
|
2019-11-15 14:35:25 +08:00
|
|
|
<Switch checked={!!state.expandable} onChange={this.handleExpandChange} />
|
2019-09-04 18:12:57 +08:00
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Checkbox">
|
|
|
|
<Switch checked={!!state.rowSelection} onChange={this.handleRowSelectionChange} />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Fixed Header">
|
2019-11-15 14:35:25 +08:00
|
|
|
<Switch checked={!!yScroll} onChange={this.handleYScrollChange} />
|
2019-09-04 18:12:57 +08:00
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Has Data">
|
|
|
|
<Switch checked={!!state.hasData} onChange={this.handleDataChange} />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Ellipsis">
|
|
|
|
<Switch checked={!!state.ellipsis} onChange={this.handleEllipsisChange} />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Size">
|
|
|
|
<Radio.Group value={state.size} onChange={this.handleSizeChange}>
|
|
|
|
<Radio.Button value="default">Default</Radio.Button>
|
|
|
|
<Radio.Button value="middle">Middle</Radio.Button>
|
|
|
|
<Radio.Button value="small">Small</Radio.Button>
|
|
|
|
</Radio.Group>
|
|
|
|
</Form.Item>
|
2019-11-15 14:35:25 +08:00
|
|
|
<Form.Item label="Table Scroll">
|
|
|
|
<Radio.Group value={xScroll} onChange={this.handleXScrollChange}>
|
|
|
|
<Radio.Button value={undefined}>Unset</Radio.Button>
|
|
|
|
<Radio.Button value="scroll">Scroll</Radio.Button>
|
|
|
|
<Radio.Button value="fixed">Fixed Columns</Radio.Button>
|
|
|
|
</Radio.Group>
|
|
|
|
</Form.Item>
|
2019-09-04 18:12:57 +08:00
|
|
|
<Form.Item label="Table Layout">
|
|
|
|
<Radio.Group value={state.tableLayout} onChange={this.handleTableLayoutChange}>
|
|
|
|
<Radio.Button value={undefined}>Unset</Radio.Button>
|
|
|
|
<Radio.Button value="fixed">Fixed</Radio.Button>
|
|
|
|
</Radio.Group>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Pagination">
|
|
|
|
<Radio.Group
|
|
|
|
value={state.pagination ? state.pagination.position : 'none'}
|
|
|
|
onChange={this.handlePaginationChange}
|
|
|
|
>
|
|
|
|
<Radio.Button value="top">Top</Radio.Button>
|
|
|
|
<Radio.Button value="bottom">Bottom</Radio.Button>
|
|
|
|
<Radio.Button value="both">Both</Radio.Button>
|
|
|
|
<Radio.Button value="none">None</Radio.Button>
|
|
|
|
</Radio.Group>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
<Table
|
|
|
|
{...this.state}
|
2019-11-15 14:35:25 +08:00
|
|
|
columns={tableColumns}
|
2019-09-04 18:12:57 +08:00
|
|
|
dataSource={state.hasData ? data : null}
|
2019-11-15 14:35:25 +08:00
|
|
|
scroll={scroll}
|
2019-09-04 18:12:57 +08:00
|
|
|
/>
|
2016-11-02 15:09:54 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(<Demo />, mountNode);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|
2016-11-02 15:09:54 +08:00
|
|
|
|
|
|
|
<style>
|
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>
|