You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

611 lines
18 KiB

10 years ago
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';
9 years ago
import Icon from '../icon';
import objectAssign from 'object-assign';
import Spin from '../spin';
import classNames from 'classnames';
10 years ago
9 years ago
function noop() {
}
const defaultLocale = {
filterTitle: '筛选',
filterConfirm: '确定',
filterReset: '重置',
emptyText: '暂无数据',
};
const defaultPagination = {
pageSize: 10,
current: 1,
onChange: noop,
onShowSizeChange: noop,
};
let AntTable = React.createClass({
9 years ago
getInitialState() {
10 years ago
return {
9 years ago
// 减少状态
selectedRowKeys: this.props.selectedRowKeys || [],
9 years ago
filters: {},
selectionDirty: false,
9 years ago
sortColumn: '',
sortOrder: '',
sorter: null,
radioIndex: null,
pagination: this.hasPagination() ?
objectAssign({}, defaultPagination, this.props.pagination) :
{},
10 years ago
};
},
9 years ago
10 years ago
getDefaultProps() {
return {
9 years ago
dataSource: [],
prefixCls: 'ant-table',
10 years ago
useFixedHeader: false,
10 years ago
rowSelection: null,
className: '',
size: 'large',
loading: false,
bordered: false,
indentSize: 20,
onChange: noop,
locale: {}
10 years ago
};
},
9 years ago
propTypes: {
dataSource: React.PropTypes.array,
9 years ago
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));
},
9 years ago
componentWillReceiveProps(nextProps) {
9 years ago
if (('pagination' in nextProps) && nextProps.pagination !== false) {
this.setState({
pagination: objectAssign({}, this.state.pagination, nextProps.pagination)
});
}