add loading prop for table

This commit is contained in:
afc163 2015-11-03 18:16:16 +08:00
parent a3a7854cad
commit 7a9c536569
3 changed files with 68 additions and 2 deletions

View File

@ -0,0 +1,59 @@
# 加载中的表格
- order: 15
用属性 `loading` 控制表格加载中状态。
---
````jsx
import { Table, Button } from 'antd';
const columns = [{
title: '姓名',
dataIndex: 'name'
}, {
title: '年龄',
dataIndex: 'age'
}, {
title: '住址',
dataIndex: 'address'
}];
const data = [{
key: '1',
name: '胡彦斌',
age: 32,
address: '西湖区湖底公园1号'
}, {
key: '2',
name: '胡彦祖',
age: 42,
address: '西湖区湖底公园1号'
}, {
key: '3',
name: '李大嘴',
age: 32,
address: '西湖区湖底公园1号'
}];
const App = React.createClass({
getInitialState() {
return {
loading: false
};
},
toggleLoading() {
this.setState({
loading: !this.state.loading
});
},
render() {
return <div>
<Table columns={columns} dataSource={data} loading={this.state.loading} />
<Button onClick={this.toggleLoading}>切换 loading 状态</Button>
</div>;
}
})
ReactDOM.render(<App />, document.getElementById('components-table-demo-loading'));
````

View File

@ -48,7 +48,7 @@ let AntTable = React.createClass({
dataSource: this.props.dataSource,
filters: {},
dirty: false,
loading: false,
loading: this.props.loading,
sortColumn: '',
sortOrder: '',
sorter: null,
@ -67,6 +67,7 @@ let AntTable = React.createClass({
rowSelection: null,
className: '',
size: 'default',
loading: false,
bordered: false,
onChange: function () {
}
@ -113,6 +114,11 @@ let AntTable = React.createClass({
filters: {}
});
}
if ('loading' in nextProps) {
this.setState({
loading: nextProps.loading
});
}
},
hasPagination(pagination) {
@ -597,7 +603,7 @@ let AntTable = React.createClass({
className={classString}
expandIconAsCell={expandIconAsCell} />
);
if (this.state.loading && !this.isLocalDataSource()) {
if (this.state.loading) {
// if there is no pagination or no data, the height of spin should decrease by half of pagination
let paginationPatchClass = (this.hasPagination() && data && data.length !== 0)
? 'ant-table-with-pagination'

View File

@ -69,6 +69,7 @@ var dataSource = new Table.DataSource({
| rowKey | 表格列 key 的取值 | Function(recode, index):string | | record.key |
| expandIconAsCell | 设置展开 Icon 是否单独一列 | Boolean | | true |
| onChange | 分页、排序、筛选变化时触发 | Function(pagination, filters, sorter) | | |
| loading | 页面是否加载中 | Boolean | | false |
### Column