2015-07-09 11:41:36 +08:00
|
|
|
import React from 'react';
|
2016-03-21 21:16:38 +08:00
|
|
|
import RcTable from 'rc-table';
|
2015-07-15 17:22:58 +08:00
|
|
|
import Checkbox from '../checkbox';
|
2015-10-09 17:14:09 +08:00
|
|
|
import Radio from '../radio';
|
2015-08-17 18:14:39 +08:00
|
|
|
import FilterDropdown from './filterDropdown';
|
2015-07-14 15:35:17 +08:00
|
|
|
import Pagination from '../pagination';
|
2015-11-20 11:05:34 +08:00
|
|
|
import Icon from '../icon';
|
2015-10-27 10:34:05 +08:00
|
|
|
import Spin from '../spin';
|
2015-11-26 14:44:28 +08:00
|
|
|
import classNames from 'classnames';
|
2016-03-16 16:39:53 +08:00
|
|
|
import { flatArray } from './util';
|
2015-07-09 11:41:36 +08:00
|
|
|
|
2015-07-31 10:40:23 +08:00
|
|
|
function noop() {
|
|
|
|
}
|
2015-07-27 19:58:51 +08:00
|
|
|
|
2015-11-24 15:58:50 +08:00
|
|
|
const defaultLocale = {
|
|
|
|
filterTitle: '筛选',
|
|
|
|
filterConfirm: '确定',
|
2015-12-16 18:14:22 +08:00
|
|
|
filterReset: '重置',
|
|
|
|
emptyText: '暂无数据',
|
2015-11-24 15:58:50 +08:00
|
|
|
};
|
|
|
|
|
2016-01-08 16:53:25 +08:00
|
|
|
const defaultPagination = {
|
|
|
|
pageSize: 10,
|
|
|
|
current: 1,
|
|
|
|
onChange: noop,
|
|
|
|
onShowSizeChange: noop,
|
|
|
|
};
|
|
|
|
|
2016-03-28 20:52:54 +08:00
|
|
|
const Table = React.createClass({
|
2015-07-31 10:40:23 +08:00
|
|
|
getInitialState() {
|
2015-07-10 17:47:53 +08:00
|
|
|
return {
|
2015-07-31 10:40:23 +08:00
|
|
|
// 减少状态
|
2016-01-01 22:34:59 +08:00
|
|
|
selectedRowKeys: this.props.selectedRowKeys || [],
|
2016-03-29 16:35:06 +08:00
|
|
|
filters: this.getFiltersFromColumns(),
|
2015-11-05 17:30:24 +08:00
|
|
|
selectionDirty: false,
|
2016-03-29 15:03:31 +08:00
|
|
|
...this.getSortStateFromColumns(),
|
2016-01-08 16:53:25 +08:00
|
|
|
pagination: this.hasPagination() ?
|
2016-03-25 18:16:48 +08:00
|
|
|
{
|
|
|
|
size: this.props.size,
|
|
|
|
...defaultPagination,
|
|
|
|
...this.props.pagination,
|
|
|
|
} : {},
|
2015-07-10 17:47:53 +08:00
|
|
|
};
|
|
|
|
},
|
2015-07-31 10:40:23 +08:00
|
|
|
|
2015-07-09 11:41:36 +08:00
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
2015-12-10 15:25:48 +08:00
|
|
|
dataSource: [],
|
2015-07-09 14:51:48 +08:00
|
|
|
prefixCls: 'ant-table',
|
2015-07-10 17:47:53 +08:00
|
|
|
useFixedHeader: false,
|
2015-07-10 17:50:48 +08:00
|
|
|
rowSelection: null,
|
2015-10-22 17:27:53 +08:00
|
|
|
className: '',
|
2015-11-26 14:44:28 +08:00
|
|
|
size: 'large',
|
2015-11-03 18:16:16 +08:00
|
|
|
loading: false,
|
2015-10-19 11:29:36 +08:00
|
|
|
bordered: false,
|
2015-12-29 14:36:38 +08:00
|
|
|
indentSize: 20,
|
2015-11-24 15:58:50 +08:00
|
|
|
onChange: noop,
|
|
|
|
locale: {}
|
2015-07-09 11:41:36 +08:00
|
|
|
};
|
|
|
|
},
|
2015-07-31 10:40:23 +08:00
|
|
|
|
2015-08-05 10:58:21 +08:00
|
|
|
propTypes: {
|
2015-12-09 21:49:32 +08:00
|
|
|
dataSource: React.PropTypes.array,
|
2015-12-10 15:25:48 +08:00
|
|
|
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,
|
2015-08-05 10:58:21 +08:00
|
|
|
},
|
|
|
|
|
2016-03-03 17:43:38 +08:00
|
|
|
contextTypes: {
|
2016-03-05 16:39:27 +08:00
|
|
|
antLocale: React.PropTypes.object,
|
2016-03-03 17:43:38 +08:00
|
|
|
},
|
|
|
|
|
2015-10-09 17:14:09 +08:00
|
|
|
getDefaultSelection() {
|
2016-01-01 19:00:34 +08:00
|
|
|
if (!this.props.rowSelection || !this.props.rowSelection.getCheckboxProps) {
|
|
|
|
return [];
|
2015-10-09 17:14:09 +08:00
|
|
|
}
|
2016-03-16 16:39:53 +08:00
|
|
|
return this.getFlatCurrentPageData()
|
2016-01-01 19:00:34 +08:00
|
|
|
.filter(item => this.props.rowSelection.getCheckboxProps(item).defaultChecked)
|
|
|
|
.map((record, rowIndex) => this.getRecordKey(record, rowIndex));
|
2015-10-09 17:14:09 +08:00
|
|
|
},
|
|
|
|
|
2016-03-03 17:43:38 +08:00
|
|
|
getLocale() {
|
|
|
|
let locale = {};
|
2016-03-05 16:39:27 +08:00
|
|
|
if (this.context.antLocale && this.context.antLocale.Table) {
|
|
|
|
locale = this.context.antLocale.Table;
|
2016-03-03 17:43:38 +08:00
|
|
|
}
|
2016-03-25 18:16:48 +08:00
|
|
|
return { ...defaultLocale, ...locale, ...this.props.locale };
|
2016-03-03 17:43:38 +08:00
|
|
|
},
|
|
|
|
|
2015-07-31 11:28:49 +08:00
|
|
|
componentWillReceiveProps(nextProps) {
|
2015-07-31 10:40:23 +08:00
|
|
|
if (('pagination' in nextProps) && nextProps.pagination !== false) {
|
2015-09-26 00:55:55 +08:00
|
|
|
this.setState({
|
2016-03-25 18:16:48 +08:00
|
|
|
pagination: { ...defaultPagination, ...this.state.pagination, ...nextProps.pagination },
|
2015-09-26 00:55:55 +08:00
|
|
|
});
|
2015-07-28 14:02:18 +08:00
|
|
|
}
|
2016-01-01 22:34:59 +08:00
|
|
|
// dataSource 的变化会清空选中项
|
2015-08-27 23:55:25 +08:00
|
|
|
if ('dataSource' in nextProps &&
|
2015-11-05 17:30:24 +08:00
|
|
|
nextProps.dataSource !== this.props.dataSource) {
|
2015-09-26 00:55:55 +08:00
|
|
|
this.setState({
|
2015-11-05 17:30:24 +08:00
|
|
|
selectionDirty: false,
|
2015-11-03 18:16:16 +08:00
|
|
|
});
|
2016-01-01 22:34:59 +08:00
|
|
|
}
|
|
|
|
if (nextProps.rowSelection &&
|
|
|
|
'selectedRowKeys' in nextProps.rowSelection) {
|
|
|
|
this.setState({
|
|
|
|
selectedRowKeys: nextProps.rowSelection.selectedRowKeys || [],
|
|
|
|
});
|
|
|
|
}
|
2016-03-30 17:49:36 +08:00
|
|
|
|
|
|
|
if (this.getSortOrderColumns(nextProps.columns).length > 0) {
|
2016-03-29 15:03:31 +08:00
|
|
|
const sortState = this.getSortStateFromColumns(nextProps.columns);
|
2016-03-29 16:35:06 +08:00
|
|
|
if (sortState.sortColumn !== this.state.sortColumn ||
|
|
|
|
sortState.sortOrder !== this.state.sortOrder) {
|
2016-03-29 12:13:25 +08:00
|
|
|
this.setState(sortState);
|
|
|
|
}
|
|
|
|
}
|
2016-03-30 17:49:36 +08:00
|
|
|
|
|
|
|
const filteredValueColumns = this.getFilteredValueColumns(nextProps.columns);
|
|
|
|
if (filteredValueColumns.length > 0) {
|
|
|
|
const filtersFromColumns = this.getFiltersFromColumns(nextProps.columns);
|
|
|
|
const newFilters = { ...this.state.filters };
|
|
|
|
Object.keys(filtersFromColumns).forEach(key => {
|
|
|
|
newFilters[key] = filtersFromColumns[key];
|
|
|
|
});
|
2016-03-30 17:56:37 +08:00
|
|
|
if (this.isFiltersChanged(newFilters)) {
|
|
|
|
this.setState({ filters: newFilters });
|
|
|
|
}
|
2016-03-29 16:35:06 +08:00
|
|
|
}
|
2016-01-01 22:34:59 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
setSelectedRowKeys(selectedRowKeys) {
|
|
|
|
if (this.props.rowSelection &&
|
|
|
|
!('selectedRowKeys' in this.props.rowSelection)) {
|
|
|
|
this.setState({ selectedRowKeys });
|
|
|
|
}
|
|
|
|
if (this.props.rowSelection && this.props.rowSelection.onChange) {
|
2016-03-16 16:39:53 +08:00
|
|
|
const data = this.getFlatCurrentPageData();
|
2016-03-16 16:03:16 +08:00
|
|
|
const selectedRows = data.filter(
|
|
|
|
(row, i) => selectedRowKeys.indexOf(this.getRecordKey(row, i)) >= 0
|
|
|
|
);
|
2016-03-02 21:56:48 +08:00
|
|
|
this.props.rowSelection.onChange(selectedRowKeys, selectedRows);
|
2015-11-03 18:16:16 +08:00
|
|
|
}
|
2015-07-28 15:20:15 +08:00
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
2015-12-27 16:20:59 +08:00
|
|
|
hasPagination() {
|
2015-12-09 21:49:32 +08:00
|
|
|
return this.props.pagination !== false;
|
2015-07-28 14:02:18 +08:00
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
2016-03-29 16:35:06 +08:00
|
|
|
isFiltersChanged(filters) {
|
|
|
|
let filtersChanged = false;
|
|
|
|
if (Object.keys(filters).length !== Object.keys(this.state.filters).length) {
|
|
|
|
filtersChanged = true;
|
|
|
|
} else {
|
|
|
|
Object.keys(filters).forEach(columnKey => {
|
|
|
|
if (filters[columnKey] !== this.state.filters[columnKey]) {
|
|
|
|
filtersChanged = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return filtersChanged;
|
|
|
|
},
|
|
|
|
|
2016-03-30 17:49:36 +08:00
|
|
|
getSortOrderColumns(columns) {
|
|
|
|
return (columns || this.props.columns || []).filter(column => 'sortOrder' in column);
|
2016-03-29 16:35:06 +08:00
|
|
|
},
|
|
|
|
|
2016-03-30 17:49:36 +08:00
|
|
|
getFilteredValueColumns(columns) {
|
|
|
|
return (columns || this.props.columns || []).filter(column => 'filteredValue' in column);
|
2016-03-29 16:35:06 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
getFiltersFromColumns(columns) {
|
|
|
|
let filters = {};
|
2016-03-30 17:49:36 +08:00
|
|
|
this.getFilteredValueColumns(columns).forEach(col => {
|
|
|
|
filters[this.getColumnKey(col)] = col.filteredValue;
|
2016-03-29 16:35:06 +08:00
|
|
|
});
|
|
|
|
return filters;
|
|
|
|
},
|
|
|
|
|
2016-03-29 15:03:31 +08:00
|
|
|
getSortStateFromColumns(columns) {
|
2016-03-30 17:49:36 +08:00
|
|
|
// return fisrt column which sortOrder is not falsy
|
|
|
|
const sortedColumn =
|
|
|
|
this.getSortOrderColumns(columns).filter(col => col.sortOrder)[0];
|
2016-03-29 12:13:25 +08:00
|
|
|
if (sortedColumn) {
|
|
|
|
return {
|
|
|
|
sortColumn: sortedColumn,
|
2016-03-29 15:50:44 +08:00
|
|
|
sortOrder: sortedColumn.sortOrder,
|
2016-03-29 12:13:25 +08:00
|
|
|
};
|
|
|
|
}
|
2016-03-29 15:45:17 +08:00
|
|
|
return {
|
|
|
|
sortColumn: null,
|
|
|
|
sortOrder: null,
|
|
|
|
};
|
2016-03-29 12:13:25 +08:00
|
|
|
},
|
|
|
|
|
2016-03-28 20:52:54 +08:00
|
|
|
getSorterFn() {
|
|
|
|
const { sortOrder, sortColumn } = this.state;
|
2016-03-29 15:03:31 +08:00
|
|
|
if (!sortOrder || !sortColumn ||
|
|
|
|
typeof sortColumn.sorter !== 'function') {
|
2016-03-28 20:52:54 +08:00
|
|
|
return () => {};
|
|
|
|
}
|
|
|
|
return (a, b) => {
|
|
|
|
let result = sortColumn.sorter(a, b);
|
|
|
|
if (result !== 0) {
|
|
|
|
return (sortOrder === 'descend') ? -result : result;
|
|
|
|
}
|
|
|
|
return a.index - b.index;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-07-13 16:22:02 +08:00
|
|
|
toggleSortOrder(order, column) {
|
2016-03-28 20:52:54 +08:00
|
|
|
let { sortColumn, sortOrder } = this.state;
|
2015-08-12 12:47:04 +08:00
|
|
|
// 只同时允许一列进行排序,否则会导致排序顺序的逻辑问题
|
|
|
|
let isSortColumn = this.isSortColumn(column);
|
|
|
|
if (!isSortColumn) { // 当前列未排序
|
|
|
|
sortOrder = order;
|
|
|
|
sortColumn = column;
|
|
|
|
} else { // 当前列已排序
|
|
|
|
if (sortOrder === order) { // 切换为未排序状态
|
|
|
|
sortOrder = '';
|
|
|
|
sortColumn = null;
|
|
|
|
} else { // 切换为排序状态
|
|
|
|
sortOrder = order;
|
|
|
|
}
|
|
|
|
}
|
2015-10-19 11:29:36 +08:00
|
|
|
const newState = {
|
|
|
|
sortOrder,
|
|
|
|
sortColumn,
|
|
|
|
};
|
2016-03-30 17:49:36 +08:00
|
|
|
|
2016-03-29 15:03:31 +08:00
|
|
|
// Controlled
|
2016-03-30 17:56:37 +08:00
|
|
|
if (this.getSortOrderColumns().length === 0) {
|
2016-03-29 15:03:31 +08:00
|
|
|
this.setState(newState);
|
|
|
|
}
|
2016-03-30 17:49:36 +08:00
|
|
|
|
2016-03-16 16:35:41 +08:00
|
|
|
this.props.onChange(...this.prepareParamsArguments({ ...this.state, ...newState }));
|
2015-07-13 16:22:02 +08:00
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
2016-01-07 14:21:29 +08:00
|
|
|
handleFilter(column, nextFilters) {
|
2016-03-25 18:16:48 +08:00
|
|
|
const filters = {
|
|
|
|
...this.state.filters,
|
2016-03-29 16:35:06 +08:00
|
|
|
[this.getColumnKey(column)]: nextFilters,
|
2016-03-25 18:16:48 +08:00
|
|
|
};
|
2015-12-09 15:59:54 +08:00
|
|
|
// Remove filters not in current columns
|
|
|
|
const currentColumnKeys = this.props.columns.map(c => this.getColumnKey(c));
|
|
|
|
Object.keys(filters).forEach((columnKey) => {
|
|
|
|
if (currentColumnKeys.indexOf(columnKey) < 0) {
|
|
|
|
delete filters[columnKey];
|
|
|
|
}
|
|
|
|
});
|
2016-03-30 17:49:36 +08:00
|
|
|
|
2015-10-19 11:29:36 +08:00
|
|
|
const newState = {
|
2015-11-05 17:30:24 +08:00
|
|
|
selectionDirty: false,
|
2015-10-19 11:29:36 +08:00
|
|
|
};
|
2016-03-30 17:49:36 +08:00
|
|
|
const filtersToSetState = { ...filters };
|
|
|
|
// Remove filters which is controlled
|
|
|
|
this.getFilteredValueColumns().forEach(col => {
|
|
|
|
const columnKey = this.getColumnKey(col);
|
|
|
|
if (columnKey) {
|
|
|
|
delete filtersToSetState[columnKey];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (Object.keys(filtersToSetState).length > 0) {
|
|
|
|
newState.filters = filtersToSetState;
|
2016-03-29 16:35:06 +08:00
|
|
|
}
|
2016-03-30 17:49:36 +08:00
|
|
|
this.setState(newState, () => {
|
|
|
|
this.props.onChange(...this.prepareParamsArguments({
|
|
|
|
...this.state, selectionDirty: false, filters,
|
|
|
|
}));
|
|
|
|
});
|
2015-07-13 18:42:08 +08:00
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
2015-07-31 10:40:23 +08:00
|
|
|
handleSelect(record, rowIndex, e) {
|
2016-01-01 19:49:02 +08:00
|
|
|
const checked = e.target.checked;
|
|
|
|
const defaultSelection = this.state.selectionDirty ? [] : this.getDefaultSelection();
|
2015-10-09 17:14:09 +08:00
|
|
|
let selectedRowKeys = this.state.selectedRowKeys.concat(defaultSelection);
|
2015-07-31 10:40:23 +08:00
|
|
|
let key = this.getRecordKey(record, rowIndex);
|
2015-07-14 15:35:17 +08:00
|
|
|
if (checked) {
|
2015-07-31 10:40:23 +08:00
|
|
|
selectedRowKeys.push(this.getRecordKey(record, rowIndex));
|
2015-07-14 15:35:17 +08:00
|
|
|
} else {
|
2015-07-31 10:40:23 +08:00
|
|
|
selectedRowKeys = selectedRowKeys.filter((i) => {
|
|
|
|
return key !== i;
|
2015-07-14 15:35:17 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
this.setState({
|
2016-01-01 22:34:59 +08:00
|
|
|
selectionDirty: true,
|
2015-10-09 17:14:09 +08:00
|
|
|
});
|
2016-01-01 22:34:59 +08:00
|
|
|
this.setSelectedRowKeys(selectedRowKeys);
|
2015-10-09 17:14:09 +08:00
|
|
|
if (this.props.rowSelection.onSelect) {
|
2016-03-16 16:39:53 +08:00
|
|
|
let data = this.getFlatCurrentPageData();
|
2015-10-09 17:14:09 +08:00
|
|
|
let selectedRows = data.filter((row, i) => {
|
|
|
|
return selectedRowKeys.indexOf(this.getRecordKey(row, i)) >= 0;
|
|
|
|
});
|
|
|
|
this.props.rowSelection.onSelect(record, checked, selectedRows);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-01-07 17:46:46 +08:00
|
|
|
handleRadioSelect(record, rowIndex, e) {
|
2016-01-01 19:49:02 +08:00
|
|
|
const checked = e.target.checked;
|
|
|
|
const defaultSelection = this.state.selectionDirty ? [] : this.getDefaultSelection();
|
2015-10-09 17:14:09 +08:00
|
|
|
let selectedRowKeys = this.state.selectedRowKeys.concat(defaultSelection);
|
|
|
|
let key = this.getRecordKey(record, rowIndex);
|
|
|
|
selectedRowKeys = [key];
|
|
|
|
this.setState({
|
2016-01-01 22:34:59 +08:00
|
|
|
selectionDirty: true,
|
2015-07-14 15:35:17 +08:00
|
|
|
});
|
2016-01-01 22:34:59 +08:00
|
|
|
this.setSelectedRowKeys(selectedRowKeys);
|
2015-07-14 15:35:17 +08:00
|
|
|
if (this.props.rowSelection.onSelect) {
|
2016-03-16 16:39:53 +08:00
|
|
|
let data = this.getFlatCurrentPageData();
|
2015-07-31 10:40:23 +08:00
|
|
|
let selectedRows = data.filter((row, i) => {
|
|
|
|
return selectedRowKeys.indexOf(this.getRecordKey(row, i)) >= 0;
|
2015-07-15 20:22:56 +08:00
|
|
|
});
|
2015-07-31 10:40:23 +08:00
|
|
|
this.props.rowSelection.onSelect(record, checked, selectedRows);
|
2015-07-14 15:35:17 +08:00
|
|
|
}
|
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
2015-07-16 14:41:28 +08:00
|
|
|
handleSelectAllRow(e) {
|
2016-01-01 19:49:02 +08:00
|
|
|
const checked = e.target.checked;
|
2016-03-16 16:39:53 +08:00
|
|
|
const data = this.getFlatCurrentPageData();
|
2016-01-01 19:49:02 +08:00
|
|
|
const defaultSelection = this.state.selectionDirty ? [] : this.getDefaultSelection();
|
|
|
|
const selectedRowKeys = this.state.selectedRowKeys.concat(defaultSelection);
|
|
|
|
const changableRowKeys = data.filter(item =>
|
|
|
|
!this.props.rowSelection.getCheckboxProps ||
|
|
|
|
!this.props.rowSelection.getCheckboxProps(item).disabled
|
|
|
|
).map((item, i) => this.getRecordKey(item, i));
|
2016-03-02 23:42:44 +08:00
|
|
|
|
|
|
|
// 记录变化的列
|
|
|
|
const changeRowKeys = [];
|
2016-01-01 19:49:02 +08:00
|
|
|
if (checked) {
|
|
|
|
changableRowKeys.forEach(key => {
|
|
|
|
if (selectedRowKeys.indexOf(key) < 0) {
|
|
|
|
selectedRowKeys.push(key);
|
2016-03-02 23:42:44 +08:00
|
|
|
changeRowKeys.push(key);
|
2016-01-01 19:49:02 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
changableRowKeys.forEach(key => {
|
|
|
|
if (selectedRowKeys.indexOf(key) >= 0) {
|
|
|
|
selectedRowKeys.splice(selectedRowKeys.indexOf(key), 1);
|
2016-03-02 23:42:44 +08:00
|
|
|
changeRowKeys.push(key);
|
2016-01-01 19:49:02 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-07-15 20:22:56 +08:00
|
|
|
this.setState({
|
2016-01-01 22:34:59 +08:00
|
|
|
selectionDirty: true,
|
2015-07-14 15:35:17 +08:00
|
|
|
});
|
2016-01-01 22:34:59 +08:00
|
|
|
this.setSelectedRowKeys(selectedRowKeys);
|
2015-07-14 15:35:17 +08:00
|
|
|
if (this.props.rowSelection.onSelectAll) {
|
2016-03-02 23:42:44 +08:00
|
|
|
const selectedRows = data.filter((row, i) =>
|
|
|
|
selectedRowKeys.indexOf(this.getRecordKey(row, i)) >= 0);
|
|
|
|
const changeRows = data.filter((row, i) =>
|
|
|
|
changeRowKeys.indexOf(this.getRecordKey(row, i)) >= 0);
|
|
|
|
this.props.rowSelection.onSelectAll(checked, selectedRows, changeRows);
|
2015-07-13 18:42:08 +08:00
|
|
|
}
|
2015-07-13 17:40:17 +08:00
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
2015-07-28 12:26:54 +08:00
|
|
|
handlePageChange(current) {
|
2016-04-01 00:57:03 +08:00
|
|
|
const props = this.props;
|
2016-03-25 18:16:48 +08:00
|
|
|
let pagination = { ...this.state.pagination };
|
2015-07-28 12:26:54 +08:00
|
|
|
if (current) {
|
|
|
|
pagination.current = current;
|
|
|
|
} else {
|
|
|
|
pagination.current = pagination.current || 1;
|
|
|
|
}
|
2016-01-08 15:28:32 +08:00
|
|
|
pagination.onChange(pagination.current);
|
|
|
|
|
2015-10-19 11:29:36 +08:00
|
|
|
const newState = {
|
2015-11-05 17:30:24 +08:00
|
|
|
selectionDirty: false,
|
2016-04-01 00:57:03 +08:00
|
|
|
pagination,
|
2015-10-19 11:29:36 +08:00
|
|
|
};
|
2016-04-01 00:57:03 +08:00
|
|
|
// Controlled current prop will not respond user interaction
|
|
|
|
if (props.pagination && 'current' in props.pagination) {
|
|
|
|
newState.pagination = {
|
|
|
|
...pagination,
|
|
|
|
current: this.state.pagination.current,
|
|
|
|
};
|
|
|
|
}
|
2015-12-09 21:49:32 +08:00
|
|
|
this.setState(newState);
|
2016-04-01 00:57:03 +08:00
|
|
|
|
|
|
|
this.props.onChange(...this.prepareParamsArguments({
|
|
|
|
...this.state,
|
|
|
|
selectionDirty: false,
|
|
|
|
pagination,
|
|
|
|
}));
|
2015-07-14 15:35:17 +08:00
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
2015-10-09 17:14:09 +08:00
|
|
|
renderSelectionRadio(value, record, index) {
|
|
|
|
let rowIndex = this.getRecordKey(record, index); // 从 1 开始
|
|
|
|
let props = {};
|
|
|
|
if (this.props.rowSelection.getCheckboxProps) {
|
|
|
|
props = this.props.rowSelection.getCheckboxProps.call(this, record);
|
|
|
|
}
|
2015-11-05 17:30:24 +08:00
|
|
|
let checked;
|
|
|
|
if (this.state.selectionDirty) {
|
2016-04-06 23:29:32 +08:00
|
|
|
checked = this.state.selectedRowKeys.indexOf(rowIndex) >= 0;
|
2015-11-05 17:30:24 +08:00
|
|
|
} else {
|
2016-04-06 23:29:32 +08:00
|
|
|
checked = (this.state.selectedRowKeys.indexOf(rowIndex) >= 0 ||
|
2015-11-05 17:30:24 +08:00
|
|
|
this.getDefaultSelection().indexOf(rowIndex) >= 0);
|
|
|
|
}
|
2016-01-07 14:21:29 +08:00
|
|
|
return (
|
2016-01-07 17:46:46 +08:00
|
|
|
<Radio disabled={props.disabled}
|
2016-03-30 17:06:19 +08:00
|
|
|
onChange={(e) => this.handleRadioSelect(record, rowIndex, e)}
|
2016-02-22 10:52:30 +08:00
|
|
|
value={rowIndex} checked={checked} />
|
2016-01-07 14:21:29 +08:00
|
|
|
);
|
2015-10-09 17:14:09 +08:00
|
|
|
},
|
|
|
|
|
2015-07-14 15:35:17 +08:00
|
|
|
renderSelectionCheckBox(value, record, index) {
|
2015-07-31 10:40:23 +08:00
|
|
|
let rowIndex = this.getRecordKey(record, index); // 从 1 开始
|
2015-11-05 17:30:24 +08:00
|
|
|
let checked;
|
|
|
|
if (this.state.selectionDirty) {
|
|
|
|
checked = this.state.selectedRowKeys.indexOf(rowIndex) >= 0;
|
|
|
|
} else {
|
|
|
|
checked = (this.state.selectedRowKeys.indexOf(rowIndex) >= 0 ||
|
|
|
|
this.getDefaultSelection().indexOf(rowIndex) >= 0);
|
|
|
|
}
|
2015-10-09 17:14:09 +08:00
|
|
|
let props = {};
|
|
|
|
if (this.props.rowSelection.getCheckboxProps) {
|
|
|
|
props = this.props.rowSelection.getCheckboxProps.call(this, record);
|
|
|
|
}
|
2016-01-07 14:21:29 +08:00
|
|
|
return (
|
|
|
|
<Checkbox checked={checked} disabled={props.disabled}
|
2016-03-30 17:06:19 +08:00
|
|
|
onChange={(e) => this.handleSelect(record, rowIndex, e)} />
|
2016-01-07 14:21:29 +08:00
|
|
|
);
|
2015-07-31 10:40:23 +08:00
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
|
|
|
getRecordKey(record, index) {
|
2015-11-16 15:39:40 +08:00
|
|
|
if (this.props.rowKey) {
|
|
|
|
return this.props.rowKey(record, index);
|
|
|
|
}
|
2015-07-31 10:40:23 +08:00
|
|
|
return record.key || index;
|
2015-07-14 15:35:17 +08:00
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
2015-07-14 15:35:17 +08:00
|
|
|
renderRowSelection() {
|
2015-07-31 10:40:23 +08:00
|
|
|
let columns = this.props.columns.concat();
|
2015-07-14 15:35:17 +08:00
|
|
|
if (this.props.rowSelection) {
|
2016-03-16 16:39:53 +08:00
|
|
|
let data = this.getFlatCurrentPageData().filter((item) => {
|
2015-12-16 10:31:08 +08:00
|
|
|
if (this.props.rowSelection.getCheckboxProps) {
|
|
|
|
return !this.props.rowSelection.getCheckboxProps(item).disabled;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2015-07-31 10:40:23 +08:00
|
|
|
let checked;
|
|
|
|
if (!data.length) {
|
|
|
|
checked = false;
|
|
|
|
} else {
|
2015-11-16 15:57:36 +08:00
|
|
|
checked = this.state.selectionDirty
|
|
|
|
? data.every((item, i) =>
|
|
|
|
this.state.selectedRowKeys.indexOf(this.getRecordKey(item, i)) >= 0)
|
2016-01-15 17:43:37 +08:00
|
|
|
: (
|
|
|
|
data.every((item, i) =>
|
|
|
|
this.state.selectedRowKeys.indexOf(this.getRecordKey(item, i)) >= 0) ||
|
|
|
|
data.every((item) =>
|
2015-11-16 15:57:36 +08:00
|
|
|
this.props.rowSelection.getCheckboxProps &&
|
2016-01-15 17:43:37 +08:00
|
|
|
this.props.rowSelection.getCheckboxProps(item).defaultChecked)
|
|
|
|
);
|
2015-07-31 10:40:23 +08:00
|
|
|
}
|
2015-10-09 17:14:09 +08:00
|
|
|
let selectionColumn;
|
|
|
|
if (this.props.rowSelection.type === 'radio') {
|
|
|
|
selectionColumn = {
|
|
|
|
key: 'selection-column',
|
|
|
|
render: this.renderSelectionRadio,
|
|
|
|
className: 'ant-table-selection-column'
|
|
|
|
};
|
|
|
|
} else {
|
2016-01-01 19:07:28 +08:00
|
|
|
const checkboxAllDisabled = data.every(item =>
|
|
|
|
this.props.rowSelection.getCheckboxProps &&
|
|
|
|
this.props.rowSelection.getCheckboxProps(item).disabled);
|
|
|
|
const checkboxAll = (
|
|
|
|
<Checkbox checked={checked}
|
2016-01-07 17:46:46 +08:00
|
|
|
disabled={checkboxAllDisabled}
|
|
|
|
onChange={this.handleSelectAllRow} />
|
2016-01-01 19:07:28 +08:00
|
|
|
);
|
2015-10-09 17:14:09 +08:00
|
|
|
selectionColumn = {
|
|
|
|
key: 'selection-column',
|
|
|
|
title: checkboxAll,
|
|
|
|
render: this.renderSelectionCheckBox,
|
|
|
|
className: 'ant-table-selection-column'
|
|
|
|
};
|
|
|
|
}
|
2016-03-02 16:01:36 +08:00
|
|
|
if (columns[0] && columns[0].key === 'selection-column') {
|
2015-07-14 15:35:17 +08:00
|
|
|
columns[0] = selectionColumn;
|
|
|
|
} else {
|
|
|
|
columns.unshift(selectionColumn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return columns;
|
|
|
|
},
|
2015-07-31 10:40:23 +08:00
|
|
|
|
2015-08-12 12:47:04 +08:00
|
|
|
getColumnKey(column, index) {
|
|
|
|
return column.key || column.dataIndex || index;
|
|
|
|
},
|
|
|
|
|
|
|
|
isSortColumn(column) {
|
2016-03-28 20:52:54 +08:00
|
|
|
const { sortColumn } = this.state;
|
|
|
|
if (!column || !sortColumn) {
|
2015-08-12 12:47:04 +08:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-28 20:52:54 +08:00
|
|
|
return this.getColumnKey(sortColumn) === this.getColumnKey(column);
|
2015-07-31 10:40:23 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
renderColumnsDropdown(columns) {
|
2016-03-28 20:52:54 +08:00
|
|
|
const { sortOrder } = this.state;
|
2016-03-03 17:43:38 +08:00
|
|
|
const locale = this.getLocale();
|
2016-01-07 14:21:29 +08:00
|
|
|
return columns.map((originColumn, i) => {
|
2016-03-25 18:16:48 +08:00
|
|
|
let column = { ...originColumn };
|
2015-08-12 12:47:04 +08:00
|
|
|
let key = this.getColumnKey(column, i);
|
2016-01-07 14:21:29 +08:00
|
|
|
let filterDropdown;
|
|
|
|
let sortButton;
|
2015-07-14 15:35:17 +08:00
|
|
|
if (column.filters && column.filters.length > 0) {
|
2015-07-31 10:40:23 +08:00
|
|
|
let colFilters = this.state.filters[key] || [];
|
2016-01-07 14:21:29 +08:00
|
|
|
filterDropdown = (
|
2015-11-24 15:58:50 +08:00
|
|
|
<FilterDropdown locale={locale} column={column}
|
2016-01-07 17:46:46 +08:00
|
|
|
selectedKeys={colFilters}
|
2016-02-22 10:52:30 +08:00
|
|
|
confirmFilter={this.handleFilter} />
|
2016-01-07 14:21:29 +08:00
|
|
|
);
|
2015-07-13 16:22:02 +08:00
|
|
|
}
|
|
|
|
if (column.sorter) {
|
2015-08-12 12:47:04 +08:00
|
|
|
let isSortColumn = this.isSortColumn(column);
|
2015-08-12 11:50:07 +08:00
|
|
|
if (isSortColumn) {
|
|
|
|
column.className = column.className || '';
|
2016-03-28 20:52:54 +08:00
|
|
|
if (sortOrder) {
|
2015-08-12 12:47:04 +08:00
|
|
|
column.className += ' ant-table-column-sort';
|
|
|
|
}
|
2015-08-12 11:50:07 +08:00
|
|
|
}
|
2016-03-28 20:52:54 +08:00
|
|
|
const isAscend = isSortColumn && sortOrder === 'ascend';
|
|
|
|
const isDescend = isSortColumn && sortOrder === 'descend';
|
2016-01-07 14:21:29 +08:00
|
|
|
sortButton = (
|
|
|
|
<div className="ant-table-column-sorter">
|
2016-02-17 18:04:42 +08:00
|
|
|
<span className={`ant-table-column-sorter-up ${isAscend ? 'on' : 'off'}`}
|
2016-01-07 17:46:46 +08:00
|
|
|
title="↑"
|
2016-03-30 17:06:19 +08:00
|
|
|
onClick={() => this.toggleSortOrder('ascend', column)}>
|
2016-02-22 10:52:30 +08:00
|
|
|
<Icon type="caret-up" />
|
2016-01-07 14:21:29 +08:00
|
|
|
</span>
|
2016-02-17 18:04:42 +08:00
|
|
|
<span className={`ant-table-column-sorter-down ${isDescend ? 'on' : 'off'}`}
|
2016-01-07 17:46:46 +08:00
|
|
|
title="↓"
|
2016-03-30 17:06:19 +08:00
|
|
|
onClick={() => this.toggleSortOrder('descend', column)}>
|
2016-02-22 10:52:30 +08:00
|
|
|
<Icon type="caret-down" />
|
2016-01-07 14:21:29 +08:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
2015-07-13 16:22:02 +08:00
|
|
|
}
|
2016-01-07 14:21:29 +08:00
|
|
|
column.title = (
|
2016-01-20 17:14:34 +08:00
|
|
|
<span>
|
2016-01-07 14:21:29 +08:00
|
|
|
{column.title}
|
|
|
|
{sortButton}
|
|
|
|
{filterDropdown}
|
2016-01-20 17:14:34 +08:00
|
|
|
</span>
|
2016-01-07 14:21:29 +08:00
|
|
|
);
|
2015-07-13 17:40:17 +08:00
|
|
|
return column;
|
2015-07-13 16:22:02 +08:00
|
|
|
});
|
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
2015-09-23 14:28:08 +08:00
|
|
|
handleShowSizeChange(current, pageSize) {
|
2015-12-24 10:12:31 +08:00
|
|
|
const pagination = this.state.pagination;
|
2016-01-08 16:53:25 +08:00
|
|
|
pagination.onShowSizeChange(current, pageSize);
|
2016-03-17 15:13:48 +08:00
|
|
|
const nextPagination = { ...pagination, pageSize, current };
|
2015-12-24 10:12:31 +08:00
|
|
|
this.setState({ pagination: nextPagination });
|
2016-03-16 16:35:41 +08:00
|
|
|
this.props.onChange(...this.prepareParamsArguments({
|
2016-03-16 14:26:21 +08:00
|
|
|
...this.state,
|
|
|
|
pagination: nextPagination,
|
|
|
|
}));
|
2015-09-23 14:28:08 +08:00
|
|
|
},
|
|
|
|
|
2015-07-14 15:35:17 +08:00
|
|
|
renderPagination() {
|
|
|
|
// 强制不需要分页
|
2015-07-31 10:40:23 +08:00
|
|
|
if (!this.hasPagination()) {
|
|
|
|
return null;
|
2015-07-10 17:47:53 +08:00
|
|
|
}
|
2015-11-26 14:44:28 +08:00
|
|
|
let classString = classNames({
|
|
|
|
'ant-table-pagination': true,
|
2016-01-07 17:46:46 +08:00
|
|
|
mini: this.props.size === 'middle' || this.props.size === 'small',
|
2015-11-26 14:44:28 +08:00
|
|
|
});
|
2015-12-09 21:49:32 +08:00
|
|
|
let total = this.state.pagination.total || this.getLocalData().length;
|
2015-12-28 15:42:16 +08:00
|
|
|
const pageSize = this.state.pagination.pageSize;
|
2015-12-09 21:49:32 +08:00
|
|
|
return (total > 0) ?
|
2015-12-24 10:12:31 +08:00
|
|
|
<Pagination {...this.state.pagination}
|
2016-01-07 17:46:46 +08:00
|
|
|
className={classString}
|
|
|
|
onChange={this.handlePageChange}
|
|
|
|
total={total}
|
|
|
|
pageSize={pageSize}
|
|
|
|
onShowSizeChange={this.handleShowSizeChange} /> : null;
|
2015-07-10 17:47:53 +08:00
|
|
|
},
|
2015-07-31 11:28:49 +08:00
|
|
|
|
2015-07-31 10:40:23 +08:00
|
|
|
prepareParamsArguments(state) {
|
2015-07-14 18:29:43 +08:00
|
|
|
// 准备筛选、排序、分页的参数
|
2015-12-09 15:59:54 +08:00
|
|
|
const pagination = state.pagination;
|
|
|
|
const filters = state.filters;
|
|
|
|
const sorter = {};
|
2016-03-29 12:13:25 +08:00
|
|
|
if (state.sortColumn && state.sortOrder) {
|
|
|
|
sorter.column = state.sortColumn;
|
2015-07-31 10:40:23 +08:00
|
|
|
sorter.order = state.sortOrder;
|
2016-03-29 12:13:25 +08:00
|
|
|
sorter.field = state.sortColumn.dataIndex;
|
2016-03-29 15:03:31 +08:00
|
|
|
sorter.columnKey = this.getColumnKey(state.sortColumn);
|
2015-07-15 14:10:01 +08:00
|
|
|
}
|
|
|
|
return [pagination, filters, sorter];
|
2015-07-14 18:29:43 +08:00
|
|
|
},
|
2015-07-31 10:40:23 +08:00
|
|
|
|
2015-07-31 11:28:49 +08:00
|
|
|
findColumn(myKey) {
|
2016-02-26 16:31:33 +08:00
|
|
|
return this.props.columns.filter(c => this.getColumnKey(c) === myKey)[0];
|
2015-07-31 10:40:23 +08:00
|
|
|
},
|
|
|
|
|
2016-03-16 16:39:53 +08:00
|
|
|
getCurrentPageData() {
|
|
|
|
let data = this.getLocalData();
|
2016-01-07 14:21:29 +08:00
|
|
|
let current;
|
|
|
|
let pageSize;
|
2015-07-31 10:40:23 +08:00
|
|
|
let state = this.state;
|
|
|
|
// 如果没有分页的话,默认全部展示
|
|
|
|
if (!this.hasPagination()) {
|
|
|
|
pageSize = Number.MAX_VALUE;
|
|
|
|
current = 1;
|
2015-07-14 15:35:17 +08:00
|
|
|
} else {
|
2015-07-31 10:40:23 +08:00
|
|
|
pageSize = state.pagination.pageSize;
|
|
|
|
current = state.pagination.current;
|
|
|
|
}
|
|
|
|
// 分页
|
|
|
|
// ---
|
2016-03-02 21:56:48 +08:00
|
|
|
// 当数据量少于等于每页数量时,直接设置数据
|
2015-07-31 10:40:23 +08:00
|
|
|
// 否则进行读取分页数据
|
|
|
|
if (data.length > pageSize || pageSize === Number.MAX_VALUE) {
|
|
|
|
data = data.filter((item, i) => {
|
2016-02-22 10:52:30 +08:00
|
|
|
return i >= (current - 1) * pageSize && i < current * pageSize;
|
2015-07-31 10:40:23 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
2016-03-16 16:39:53 +08:00
|
|
|
getFlatCurrentPageData() {
|
|
|
|
return flatArray(this.getCurrentPageData());
|
|
|
|
},
|
|
|
|
|
|
|
|
getLocalData() {
|
2016-03-28 20:52:54 +08:00
|
|
|
const state = this.state;
|
2016-03-16 16:39:53 +08:00
|
|
|
let data = this.props.dataSource || [];
|
2015-07-31 10:40:23 +08:00
|
|
|
// 排序
|
2016-03-28 20:52:54 +08:00
|
|
|
data = data.slice(0);
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
data[i].index = i;
|
2015-07-31 10:40:23 +08:00
|
|
|
}
|
2016-03-28 20:52:54 +08:00
|
|
|
data = data.sort(this.getSorterFn());
|
2015-07-31 10:40:23 +08:00
|
|
|
// 筛选
|
|
|
|
if (state.filters) {
|
|
|
|
Object.keys(state.filters).forEach((columnKey) => {
|
|
|
|
let col = this.findColumn(columnKey);
|
2015-12-09 15:59:54 +08:00
|
|
|
if (!col) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-31 10:40:23 +08:00
|
|
|
let values = state.filters[columnKey] || [];
|
2015-07-31 11:54:46 +08:00
|
|
|
if (values.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2015-12-09 21:49:32 +08:00
|
|
|
data = col.onFilter ? data.filter(record => {
|
|
|
|
return values.some(v => col.onFilter(v, record));
|
|
|
|
}) : data;
|
2015-07-14 17:58:00 +08:00
|
|
|
});
|
2015-07-12 17:10:06 +08:00
|
|
|
}
|
2015-07-31 10:40:23 +08:00
|
|
|
return data;
|
2015-07-12 17:10:06 +08:00
|
|
|
},
|
2015-07-31 10:40:23 +08:00
|
|
|
|
|
|
|
render() {
|
2016-03-02 14:47:42 +08:00
|
|
|
const data = this.getCurrentPageData();
|
2015-07-31 10:40:23 +08:00
|
|
|
let columns = this.renderRowSelection();
|
2016-03-02 14:47:42 +08:00
|
|
|
const expandIconAsCell = this.props.expandedRowRender && this.props.expandIconAsCell !== false;
|
2016-03-03 17:43:38 +08:00
|
|
|
const locale = this.getLocale();
|
2015-11-26 14:44:28 +08:00
|
|
|
|
2016-03-02 14:47:42 +08:00
|
|
|
const classString = classNames({
|
2015-11-26 14:44:28 +08:00
|
|
|
[`ant-table-${this.props.size}`]: true,
|
|
|
|
'ant-table-bordered': this.props.bordered,
|
|
|
|
[this.props.className]: !!this.props.className,
|
|
|
|
});
|
|
|
|
|
2015-07-31 10:40:23 +08:00
|
|
|
columns = this.renderColumnsDropdown(columns);
|
2015-08-28 15:22:09 +08:00
|
|
|
columns = columns.map((column, i) => {
|
2016-03-25 18:16:48 +08:00
|
|
|
const newColumn = { ...column };
|
2016-01-07 17:46:46 +08:00
|
|
|
newColumn.key = newColumn.key || newColumn.dataIndex || i;
|
|
|
|
return newColumn;
|
2015-08-28 15:22:09 +08:00
|
|
|
});
|
2015-08-28 17:20:02 +08:00
|
|
|
let emptyText;
|
2015-09-15 11:40:58 +08:00
|
|
|
let emptyClass = '';
|
2015-08-28 17:20:02 +08:00
|
|
|
if (!data || data.length === 0) {
|
2016-01-07 14:21:29 +08:00
|
|
|
emptyText = (
|
|
|
|
<div className="ant-table-placeholder">
|
2016-02-22 10:52:30 +08:00
|
|
|
<Icon type="frown" />{locale.emptyText}
|
2016-01-07 14:21:29 +08:00
|
|
|
</div>
|
|
|
|
);
|
2015-09-15 11:40:58 +08:00
|
|
|
emptyClass = ' ant-table-empty';
|
2015-08-28 17:20:02 +08:00
|
|
|
}
|
2015-10-31 02:12:26 +08:00
|
|
|
|
2016-01-07 14:21:29 +08:00
|
|
|
let table = (
|
|
|
|
<div>
|
2016-03-21 21:16:38 +08:00
|
|
|
<RcTable {...this.props}
|
2016-01-07 17:46:46 +08:00
|
|
|
data={data}
|
|
|
|
columns={columns}
|
|
|
|
className={classString}
|
2016-03-02 16:01:36 +08:00
|
|
|
expandIconColumnIndex={(columns[0] && columns[0].key === 'selection-column') ? 1 : 0}
|
2016-01-07 17:46:46 +08:00
|
|
|
expandIconAsCell={expandIconAsCell} />
|
2016-01-07 14:21:29 +08:00
|
|
|
{emptyText}
|
|
|
|
</div>
|
|
|
|
);
|
2015-12-09 21:49:32 +08:00
|
|
|
if (this.props.loading) {
|
2016-01-07 17:46:46 +08:00
|
|
|
// if there is no pagination or no data,
|
|
|
|
// the height of spin should decrease by half of pagination
|
2016-03-02 14:47:42 +08:00
|
|
|
const paginationPatchClass = (this.hasPagination() && data && data.length !== 0)
|
2015-10-27 10:34:05 +08:00
|
|
|
? 'ant-table-with-pagination'
|
|
|
|
: 'ant-table-without-pagination';
|
2016-03-02 14:47:42 +08:00
|
|
|
const spinClassName = `${paginationPatchClass} ant-table-spin-holder`;
|
2015-11-03 17:48:56 +08:00
|
|
|
table = <Spin className={spinClassName}>{table}</Spin>;
|
2015-10-31 02:12:26 +08:00
|
|
|
}
|
2015-11-03 17:48:56 +08:00
|
|
|
return (
|
2016-02-17 18:04:42 +08:00
|
|
|
<div className={`clearfix${emptyClass}`}>
|
2015-11-03 17:48:56 +08:00
|
|
|
{table}
|
|
|
|
{this.renderPagination()}
|
|
|
|
</div>
|
|
|
|
);
|
2015-07-09 11:41:36 +08:00
|
|
|
}
|
|
|
|
});
|
2015-08-05 01:42:37 +08:00
|
|
|
|
2016-03-21 21:16:38 +08:00
|
|
|
export default Table;
|