diff --git a/components/table/Table.jsx b/components/table/Table.jsx
index f469867fc..0bc0b606f 100755
--- a/components/table/Table.jsx
+++ b/components/table/Table.jsx
@@ -24,6 +24,7 @@ import {
getAllProps,
} from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin';
+import { ConfigConsumerProps } from '../config-provider';
import { TableProps } from './interface';
function noop() {}
@@ -44,6 +45,8 @@ const defaultPagination = {
onShowSizeChange: noop,
};
+const ROW_SELECTION_COLUMN_WIDTH = '62px';
+
/**
* Avoid creating new object, so that parent component's shouldComponentUpdate
* can works appropriately。
@@ -57,7 +60,6 @@ export default {
mixins: [BaseMixin],
props: initDefaultProps(TableProps, {
dataSource: [],
- prefixCls: 'ant-table',
useFixedHeader: false,
// rowSelection: null,
size: 'default',
@@ -67,8 +69,12 @@ export default {
locale: {},
rowKey: 'key',
showHeader: true,
+ sortDirections: ['ascend', 'descend'],
}),
+ inject: {
+ configProvider: { default: () => ({}) },
+ },
// CheckboxPropsCache: {
// [key: string]: any;
// };
@@ -86,6 +92,7 @@ export default {
selectedRowKeys: getRowSelection(this.$props).selectedRowKeys || [],
selectionDirty: false,
});
+ this.prevRowSelection = this.rowSelection ? {...this.rowSelection} : this.rowSelection;
return {
...this.getDefaultSortOrder(this.columns),
// 减少状态
@@ -120,7 +127,12 @@ export default {
if (rowSelection && val.getCheckboxProps !== rowSelection.getCheckboxProps) {
this.CheckboxPropsCache = {};
}
+ } else if(val && !this.prevRowSelection) {
+ this.store.setState({
+ selectedRowKeys: [],
+ });
}
+ this.prevRowSelection = val ? {...val} : val;
},
deep: true,
},
@@ -185,19 +197,31 @@ export default {
},
getDefaultPagination(props) {
- const pagination = props.pagination || {};
+ const pagination = typeof props.pagination === 'object' ? props.pagination : {};
+ let current;
+ if ('current' in pagination) {
+ current = pagination.current;
+ } else if ('defaultCurrent' in pagination) {
+ current = pagination.defaultCurrent;
+ }
+ let pageSize;
+ if ('pageSize' in pagination) {
+ pageSize = pagination.pageSize;
+ } else if ('defaultPageSize' in pagination) {
+ pageSize = pagination.defaultPageSize;
+ }
return this.hasPagination(props)
? {
...defaultPagination,
...pagination,
- current: pagination.defaultCurrent || pagination.current || 1,
- pageSize: pagination.defaultPageSize || pagination.pageSize || 10,
+ current: current || 1,
+ pageSize: pageSize || 10,
}
: {};
},
- onRow(record, index) {
- const { prefixCls, customRow } = this;
+ onRow(prefixCls, record, index) {
+ const { customRow } = this;
const custom = customRow ? customRow(record, index) : {};
return mergeProps(custom, {
props: {
@@ -346,18 +370,18 @@ export default {
if (!column.sorter) {
return;
}
+ const sortDirections = column.sortDirections || this.sortDirections;
const { sSortOrder: sortOrder, sSortColumn: sortColumn } = this;
// 只同时允许一列进行排序,否则会导致排序顺序的逻辑问题
let newSortOrder;
// 切换另一列时,丢弃 sortOrder 的状态
- const oldSortOrder = this.isSameColumn(sortColumn, column) ? sortOrder : undefined;
- // 切换排序状态,按照降序/升序/不排序的顺序
- if (!oldSortOrder) {
- newSortOrder = 'ascend';
- } else if (oldSortOrder === 'ascend') {
- newSortOrder = 'descend';
+ if (this.isSameColumn(sortColumn, column) && sortOrder !== undefined) {
+ // 按照sortDirections的内容依次切换排序状态
+ const methodIndex = sortDirections.indexOf(sortOrder) + 1;
+ newSortOrder =
+ methodIndex === sortDirections.length ? undefined : sortDirections[methodIndex];
} else {
- newSortOrder = undefined;
+ newSortOrder = sortDirections[0];
}
const newState = {
sSortOrder: newSortOrder,
@@ -683,8 +707,15 @@ export default {
return this.$el;
},
- renderRowSelection(locale) {
- const { prefixCls, rowSelection, childrenColumnName } = this;
+ generatePopupContainerFunc() {
+ const { scroll } = this.$props;
+
+ // Use undefined to let rc component use default logic.
+ return scroll ? this.getPopupContainer : undefined;
+ },
+
+ renderRowSelection(prefixCls, locale) {
+ const { rowSelection, childrenColumnName } = this;
const columns = this.columns.concat();
if (rowSelection) {
const data = this.getFlatCurrentPageData(childrenColumnName).filter((item, index) => {
@@ -701,7 +732,7 @@ export default {
customRender: this.renderSelectionBox(rowSelection.type),
className: selectionColumnClass,
fixed: rowSelection.fixed,
- width: rowSelection.columnWidth,
+ width: rowSelection.columnWidth || ROW_SELECTION_COLUMN_WIDTH,
title: rowSelection.columnTitle,
};
if (rowSelection.type !== 'radio') {
@@ -720,7 +751,7 @@ export default {
onSelect={this.handleSelectRow}
selections={rowSelection.selections}
hideDefaultSelections={rowSelection.hideDefaultSelections}
- getPopupContainer={this.getPopupContainer}
+ getPopupContainer={this.generatePopupContainerFunc()}
/>
);
}
@@ -758,15 +789,14 @@ export default {
return this.getColumnKey(sortColumn) === this.getColumnKey(column);
},
- renderColumnsDropdown(columns, locale) {
- const { prefixCls, dropdownPrefixCls } = this;
+ renderColumnsDropdown(prefixCls, dropdownPrefixCls, columns, locale) {
const { sSortOrder: sortOrder, sFilters: filters } = this;
return treeMap(columns, (column, i) => {
const key = this.getColumnKey(column, i);
let filterDropdown;
let sortButton;
let customHeaderCell = column.customHeaderCell;
- const sortTitle = this.getColumnTitle(column.title, {}) || locale.sortTitle;
+ // const sortTitle = this.getColumnTitle(column.title, {}) || locale.sortTitle;
const isSortColumn = this.isSortColumn(column);
if ((column.filters && column.filters.length > 0) || column.filterDropdown) {
const colFilters = key in filters ? filters[key] : [];
@@ -779,26 +809,34 @@ export default {
confirmFilter={this.handleFilter}
prefixCls={`${prefixCls}-filter`}
dropdownPrefixCls={dropdownPrefixCls || 'ant-dropdown'}
- getPopupContainer={this.getPopupContainer}
+ getPopupContainer={this.generatePopupContainerFunc()}
key="filter-dropdown"
/>
);
}
if (column.sorter) {
+ const sortDirections = column.sortDirections || this.sortDirections;
const isAscend = isSortColumn && sortOrder === 'ascend';
const isDescend = isSortColumn && sortOrder === 'descend';
+ const ascend = sortDirections.indexOf('ascend') !== -1 && (
+