|
|
|
import React from 'react';
|
|
|
|
import Table from 'rc-table';
|
|
|
|
import Checkbox from '../checkbox';
|
|
|
|
import Radio from '../radio';
|
|
|
|
import FilterDropdown from './filterDropdown';
|
|
|
|
import Pagination from '../pagination';
|
|
|
|
import Icon from '../icon';
|
|
|
|
import objectAssign from 'object-assign';
|
|
|
|
import Spin from '../spin';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
function noop() {
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultLocale = {
|
|
|
|
filterTitle: '筛选',
|
|
|
|
filterConfirm: '确定',
|
|
|
|
filterReset: '重置',
|
|
|
|
emptyText: '暂无数据',
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultPagination = {
|
|
|
|
pageSize: 10,
|
|
|
|
current: 1,
|
|
|
|
onChange: noop,
|
|
|
|
onShowSizeChange: noop,
|
|
|
|
};
|
|
|
|
|
|
|
|
let AntTable = React.createClass({
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
// 减少状态
|
|
|
|
selectedRowKeys: this.props.selectedRowKeys || [],
|
|
|
|
filters: {},
|
|
|
|
selectionDirty: false,
|
|
|
|
sortColumn: '',
|
|
|
|
sortOrder: '',
|
|
|
|
sorter: null,
|
|
|
|
radioIndex: null,
|
|
|
|
pagination: this.hasPagination() ?
|
|
|
|
objectAssign({}, defaultPagination, this.props.pagination) :
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
|
|
|
dataSource: [],
|
|
|
|
prefixCls: 'ant-table',
|
|
|
|
useFixedHeader: false,
|
|
|
|
rowSelection: null,
|
|
|
|
className: '',
|
|
|
|
size: 'large',
|
|
|
|
loading: false,
|
|
|
|
bordered: false,
|
|
|
|
indentSize: 20,
|
|
|
|
onChange: noop,
|
|
|
|
locale: {}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
dataSource: React.PropTypes.array,
|
|
|
|
prefixCls: React.PropTypes.string,
|
|
|
|
useFixedHeader: React.PropTypes.bool,
|
|
|
|
rowSelection: React.PropTypes.object,
|
|
|
|
className: React.PropTypes.string,
|
|
|
|
size: React.PropTypes.string,
|
|
|
|
loading: React.PropTypes.bool,
|
|
|
|
bordered: React.PropTypes.bool,
|
|
|
|
onChange: React.PropTypes.func,
|
|
|
|
locale: React.PropTypes.object,
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultSelection() {
|
|
|
|
if (!this.props.rowSelection || !this.props.rowSelection.getCheckboxProps) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return this.getCurrentPageData()
|
|
|
|
.filter(item => this.props.rowSelection.getCheckboxProps(item).defaultChecked)
|
|
|
|
.map((record, rowIndex) => this.getRecordKey(record, rowIndex));
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (('pagination' in nextProps) && nextProps.pagination !== false) {
|
|
|
|
this.setState({
|
|
|
|
pagination: objectAssign({}, this.state.pagination, nextProps.pagination)
|
|
|
|
});
|
|
|
|
}
|
|