diff --git a/components/table/SelectionCheckboxAll.jsx b/components/table/SelectionCheckboxAll.jsx index 83e9b3abc..b51582e38 100644 --- a/components/table/SelectionCheckboxAll.jsx +++ b/components/table/SelectionCheckboxAll.jsx @@ -22,7 +22,7 @@ export default { onSelect: () => {}, }] - this.state = { + return { checked: this.getCheckState(props), indeterminate: this.getIndeterminateState(props), } @@ -32,8 +32,13 @@ export default { this.subscribe() }, - componentWillReceiveProps (nextProps) { - this.setCheckState() + watch: { + '$props': { + handler: function () { + this.setCheckState() + }, + deep: true, + }, }, beforeDestroy () { diff --git a/components/table/Table.jsx b/components/table/Table.jsx index 3219dc6f8..0cf411b60 100755 --- a/components/table/Table.jsx +++ b/components/table/Table.jsx @@ -26,7 +26,7 @@ function noop () { function stopPropagation (e) { e.stopPropagation() - if (e.nativeEvent.stopImmediatePropagation) { + if (e.nativeEvent && e.nativeEvent.stopImmediatePropagation) { e.nativeEvent.stopImmediatePropagation() } } @@ -194,33 +194,29 @@ export default { }, setSelectedRowKeys (selectedRowKeys, { selectWay, record, checked, changeRowKeys }) { - const { rowSelection = {}, $listeners: { - rowSelectionChange, - rowSelectionSelect, - rowSelectionSelectAll, - rowSelectionSelectInvert, - }} = this + const { rowSelection = {}} = this if (rowSelection && !('selectedRowKeys' in rowSelection)) { this.store.setState({ selectedRowKeys }) } const data = this.getFlatData() - if (!rowSelectionChange && !rowSelection[selectWay]) { + if (!rowSelection.onChange && !rowSelection[selectWay]) { return } const selectedRows = data.filter( (row, i) => selectedRowKeys.indexOf(this.getRecordKey(row, i)) >= 0, ) - this.$emit('rowSelectionChange', selectedRowKeys, selectedRows) - - if (selectWay === 'onSelect' && rowSelectionSelect) { - this.$emit('rowSelectionSelect', record, checked, selectedRows) - } else if (selectWay === 'onSelectAll' && rowSelectionSelectAll) { + if (rowSelection.onChange) { + rowSelection.onChange(selectedRowKeys, selectedRows) + } + if (selectWay === 'onSelect' && rowSelection.onSelect) { + rowSelection.onSelect(record, checked, selectedRows) + } else if (selectWay === 'onSelectAll' && rowSelection.onSelectAll) { const changeRows = data.filter( (row, i) => changeRowKeys.indexOf(this.getRecordKey(row, i)) >= 0, ) - this.$emit('rowSelectionSelectAll', checked, selectedRows, changeRows) - } else if (selectWay === 'onSelectInvert' && rowSelectionSelectInvert) { - this.$emit('rowSelectionSelectInvert', selectedRowKeys) + rowSelection.onSelectAll(checked, selectedRows, changeRows) + } else if (selectWay === 'onSelectInvert' && rowSelection.onSelectInvert) { + rowSelection.onSelectInvert(selectedRowKeys) } }, @@ -602,7 +598,7 @@ export default { }) const selectionColumn = { key: 'selection-column', - render: this.renderSelectionBox(rowSelection.type), + customRender: this.renderSelectionBox(rowSelection.type), className: selectionColumnClass, fixed: rowSelection.fixed, } diff --git a/components/table/demo/basic.7.md b/components/table/demo/basic.7.md deleted file mode 100644 index 332ec9843..000000000 --- a/components/table/demo/basic.7.md +++ /dev/null @@ -1,76 +0,0 @@ - -#### 基本用法 -简单的表格,最后一列是各种操作。 - - - -#### basic Usage -Simple table with actions. - - -```html - - -``` diff --git a/components/table/demo/basic.8.md b/components/table/demo/basic.8.md deleted file mode 100644 index 332ec9843..000000000 --- a/components/table/demo/basic.8.md +++ /dev/null @@ -1,76 +0,0 @@ - -#### 基本用法 -简单的表格,最后一列是各种操作。 - - - -#### basic Usage -Simple table with actions. - - -```html - - -``` diff --git a/components/table/demo/basic.9.md b/components/table/demo/basic.9.md deleted file mode 100644 index 332ec9843..000000000 --- a/components/table/demo/basic.9.md +++ /dev/null @@ -1,76 +0,0 @@ - -#### 基本用法 -简单的表格,最后一列是各种操作。 - - - -#### basic Usage -Simple table with actions. - - -```html - - -``` diff --git a/components/table/demo/basic.md b/components/table/demo/basic.md index ca0cfbfa7..b923f1dbe 100644 --- a/components/table/demo/basic.md +++ b/components/table/demo/basic.md @@ -11,23 +11,17 @@ Simple table with actions. ```html +``` diff --git a/components/table/demo/expand.md b/components/table/demo/expand.md new file mode 100644 index 000000000..cbe179d61 --- /dev/null +++ b/components/table/demo/expand.md @@ -0,0 +1,41 @@ + +#### 可展开 +当表格内容较多不能一次性完全展示时。 + + + +#### Expandable Row +When there's too much information to show and the table can't display all at once. + + +```html + + +``` diff --git a/components/table/demo/fixed-columns-header.md b/components/table/demo/fixed-columns-header.md new file mode 100644 index 000000000..736519464 --- /dev/null +++ b/components/table/demo/fixed-columns-header.md @@ -0,0 +1,61 @@ + +#### 固定头和列 +适合同时展示有大量数据和数据列。 +> 若列头与内容不对齐或出现列重复,请指定列的宽度 `width`。 +> 建议指定 `scroll.x` 为大于表格宽度的固定值或百分比。注意,且非固定列宽度之和不要超过 `scroll.x`。 + + + +#### Fixed Columns and Header +A Solution for displaying large amounts of data with long columns. +> Specify the width of columns if header and cell do not align properly. +> A fixed value which is greater than table width for `scroll.x` is recommended. The sum of unfixed columns should not greater than `scroll.x`. + + +```html + + +``` diff --git a/components/table/index.jsx b/components/table/index.jsx index 6b43b8944..9e1e80089 100644 --- a/components/table/index.jsx +++ b/components/table/index.jsx @@ -77,7 +77,11 @@ const Table = { const props = getOptionProps(this) const columns = props.columns ? this.updateColumns(props.columns) : normalize($slots.default) let { title, footer } = props - const { title: slotTitle, footer: slotFooter } = $scopedSlots + const { + title: slotTitle, + footer: slotFooter, + expandedRowRender = props.expandedRowRender, + } = $scopedSlots title = title || slotTitle footer = footer || slotFooter const tProps = { @@ -86,6 +90,7 @@ const Table = { columns, title, footer, + expandedRowRender, }, on: $listeners, } diff --git a/components/table/interface.js b/components/table/interface.js index 57e7fb151..9b08d45e1 100644 --- a/components/table/interface.js +++ b/components/table/interface.js @@ -160,7 +160,7 @@ export const SelectionBoxProps = { store: Store, type: RowSelectionType, defaultSelection: PropTypes.arrayOf(PropTypes.string), - rowIndex: PropTypes.string, + rowIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), name: PropTypes.string, disabled: PropTypes.bool, // onChange: React.ChangeEventHandler; diff --git a/components/vc-table/src/ExpandableTable.jsx b/components/vc-table/src/ExpandableTable.jsx index 7500be3e7..812e58ba2 100644 --- a/components/vc-table/src/ExpandableTable.jsx +++ b/components/vc-table/src/ExpandableTable.jsx @@ -134,8 +134,8 @@ const ExpandableTable = { } const columns = [{ key: 'extra-row', - render: () => ({ - props: { + customRender: () => ({ + attrs: { colSpan: colCount, }, children: fixed !== 'right' ? expandedRowRender(record, index, indent) : ' ', @@ -144,7 +144,7 @@ const ExpandableTable = { if (expandIconAsCell && fixed !== 'right') { columns.unshift({ key: 'expand-icon-placeholder', - render: () => null, + customRender: () => null, }) } const parentKey = ancestorKeys[ancestorKeys.length - 1]