Title: {currentData.length} items
}
- footer={currentData => Footer: {currentData.length} items
}
- />
- ,
- document.getElementById('__react-content')
-);
diff --git a/components/vc-table/src/BaseTable.jsx b/components/vc-table/src/BaseTable.jsx
index c2d0811eb..93a624224 100644
--- a/components/vc-table/src/BaseTable.jsx
+++ b/components/vc-table/src/BaseTable.jsx
@@ -5,7 +5,8 @@ import TableHeader from './TableHeader'
import TableRow from './TableRow'
import ExpandableRow from './ExpandableRow'
import { mergeProps } from '../../_util/props-util'
-
+import { connect } from '../../_util/store'
+function noop () {}
const BaseTable = {
name: 'BaseTable',
props: {
@@ -34,18 +35,18 @@ const BaseTable = {
renderRows (renderData, indent, ancestorKeys = []) {
const {
- columnManager, components,
+ columnManager, sComponents: components,
prefixCls,
childrenColumnName,
rowClassName,
// rowRef,
$listeners: {
- rowClick: onRowClick,
- rowDoubleclick: onRowDoubleClick,
- rowContextmenu: onRowContextMenu,
- rowMouseenter: onRowMouseEnter,
- rowMouseleave: onRowMouseLeave,
- row: onRow,
+ rowClick: onRowClick = noop,
+ rowDoubleclick: onRowDoubleClick = noop,
+ rowContextmenu: onRowContextMenu = noop,
+ rowMouseenter: onRowMouseEnter = noop,
+ rowMouseleave: onRowMouseLeave = noop,
+ row: onRow = noop,
},
} = this.table
const { getRowKey, fixed, expander, isAnyColumnsFixed } = this
@@ -86,6 +87,7 @@ const BaseTable = {
},
key,
on: {
+ // ...expander.on,
rowClick: onRowClick,
expandedChange: expander.handleExpandChange,
},
@@ -148,7 +150,7 @@ const BaseTable = {
},
render () {
- const { components, prefixCls, scroll, data, getBodyWrapper } = this.table
+ const { sComponents: components, prefixCls, scroll, data, getBodyWrapper } = this.table
const { expander, tableClassName, hasHead, hasBody, fixed, columns } = this
const tableStyle = {}
@@ -186,4 +188,4 @@ const BaseTable = {
},
}
-export default BaseTable
+export default connect()(BaseTable)
diff --git a/components/vc-table/src/ColGroup.jsx b/components/vc-table/src/ColGroup.jsx
index 0df1afe27..9f169e57a 100644
--- a/components/vc-table/src/ColGroup.jsx
+++ b/components/vc-table/src/ColGroup.jsx
@@ -4,13 +4,14 @@ export default {
name: 'ColGroup',
props: {
fixed: PropTypes.string,
+ columns: PropTypes.array,
},
inject: {
table: { default: {}},
},
render () {
const { fixed, table } = this
- const { prefixCls, expandIconAsCell } = table
+ const { prefixCls, expandIconAsCell, columnManager } = table
let cols = []
@@ -26,18 +27,19 @@ export default {
let leafColumns
if (fixed === 'left') {
- leafColumns = table.columnManager.leftLeafColumns()
+ leafColumns = columnManager.leftLeafColumns()
} else if (fixed === 'right') {
- leafColumns = table.columnManager.rightLeafColumns()
+ leafColumns = columnManager.rightLeafColumns()
} else {
- leafColumns = table.columnManager.leafColumns()
+ leafColumns = columnManager.leafColumns()
}
cols = cols.concat(
leafColumns.map(c => {
+ const width = typeof c.width === 'number' ? `${c.width}px` : c.width
return (
)
})
diff --git a/components/vc-table/src/ColumnManager.js b/components/vc-table/src/ColumnManager.jsx
similarity index 99%
rename from components/vc-table/src/ColumnManager.js
rename to components/vc-table/src/ColumnManager.jsx
index a90756c14..b0696baaf 100644
--- a/components/vc-table/src/ColumnManager.js
+++ b/components/vc-table/src/ColumnManager.jsx
@@ -1,8 +1,7 @@
export default class ColumnManager {
- _cached = {}
-
constructor (columns, elements) {
this.columns = columns || this.normalize(elements)
+ this._cached = {}
}
isAnyColumnsFixed () {
diff --git a/components/vc-table/src/ExpandableRow.js b/components/vc-table/src/ExpandableRow.jsx
similarity index 56%
rename from components/vc-table/src/ExpandableRow.js
rename to components/vc-table/src/ExpandableRow.jsx
index 895cd886c..77d40a0b9 100644
--- a/components/vc-table/src/ExpandableRow.js
+++ b/components/vc-table/src/ExpandableRow.jsx
@@ -1,6 +1,7 @@
import PropTypes from '../../_util/vue-types'
import ExpandIcon from './ExpandIcon'
import BaseMixin from '../../_util/BaseMixin'
+import { connect } from '../../_util/store'
const ExpandableRow = {
mixins: [BaseMixin],
@@ -32,61 +33,62 @@ const ExpandableRow = {
beforeDestroy () {
this.handleDestroy()
},
+ methods: {
+ hasExpandIcon (columnIndex) {
+ const { expandRowByClick } = this
+ return !this.expandIconAsCell &&
+ !expandRowByClick &&
+ columnIndex === this.expandIconColumnIndex
+ },
- hasExpandIcon (columnIndex) {
- const { expandRowByClick } = this
- return !this.expandIconAsCell &&
- !expandRowByClick &&
- columnIndex === this.expandIconColumnIndex
- },
+ handleExpandChange (record, event) {
+ const { expanded, rowKey } = this
+ this.__emit('expandedChange', !expanded, record, event, rowKey)
+ },
- handleExpandChange (record, event) {
- const { expanded, rowKey } = this
- this.__emit('expandedChange', !expanded, record, event, rowKey)
- },
+ handleDestroy () {
+ const { rowKey, record } = this
+ this.__emit('expandedChange', false, record, null, rowKey, true)
+ },
- handleDestroy () {
- const { rowKey, record } = this
- this.__emit('expandedChange', false, record, null, rowKey, true)
- },
+ handleRowClick (record, index, event) {
+ const { expandRowByClick } = this
+ if (expandRowByClick) {
+ this.handleExpandChange(record, event)
+ }
+ this.__emit('rowClick', record, index, event)
+ },
- handleRowClick (record, index, event) {
- const { expandRowByClick } = this
- if (expandRowByClick) {
- this.handleExpandChange(record, event)
- }
- this.__emit('rowClick', record, index, event)
- },
+ renderExpandIcon () {
+ const { prefixCls, expanded, record, needIndentSpaced } = this
- renderExpandIcon () {
- const { prefixCls, expanded, record, needIndentSpaced } = this
+ return (
+
+ )
+ },
- return (
-
- )
- },
+ renderExpandIconCell (cells) {
+ if (!this.expandIconAsCell) {
+ return
+ }
+ const { prefixCls } = this
- renderExpandIconCell (cells) {
- if (!this.expandIconAsCell) {
- return
- }
- const { prefixCls } = this
-
- cells.push(
-
- {this.renderExpandIcon()}
- |
- )
+ cells.push(
+
+ {this.renderExpandIcon()}
+ |
+ )
+ },
},
render () {
@@ -103,7 +105,6 @@ const ExpandableRow = {
this.expandIconColumnIndex = fixed !== 'right' ? this.expandIconColumnIndex : -1
const childrenData = record[childrenColumnName]
this.expandable = !!(childrenData || expandedRowRender)
-
const expandableRowProps = {
props: {
indentSize,
diff --git a/components/vc-table/src/ExpandableTable.js b/components/vc-table/src/ExpandableTable.js
deleted file mode 100644
index 025a59872..000000000
--- a/components/vc-table/src/ExpandableTable.js
+++ /dev/null
@@ -1,223 +0,0 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import { connect } from 'mini-store'
-import TableRow from './TableRow'
-import { remove } from './utils'
-
-class ExpandableTable extends React.Component {
- static propTypes = {
- expandIconAsCell: PropTypes.bool,
- expandedRowKeys: PropTypes.array,
- expandedRowClassName: PropTypes.func,
- defaultExpandAllRows: PropTypes.bool,
- defaultExpandedRowKeys: PropTypes.array,
- expandIconColumnIndex: PropTypes.number,
- expandedRowRender: PropTypes.func,
- childrenColumnName: PropTypes.string,
- indentSize: PropTypes.number,
- onExpand: PropTypes.func,
- onExpandedRowsChange: PropTypes.func,
- columnManager: PropTypes.object.isRequired,
- store: PropTypes.object.isRequired,
- prefixCls: PropTypes.string.isRequired,
- data: PropTypes.array,
- children: PropTypes.func.isRequired,
- }
-
- static defaultProps = {
- expandIconAsCell: false,
- expandedRowClassName: () => '',
- expandIconColumnIndex: 0,
- defaultExpandAllRows: false,
- defaultExpandedRowKeys: [],
- childrenColumnName: 'children',
- indentSize: 15,
- onExpand () {},
- onExpandedRowsChange () {},
- }
-
- constructor (props) {
- super(props)
-
- const {
- data,
- childrenColumnName,
- defaultExpandAllRows,
- expandedRowKeys,
- defaultExpandedRowKeys,
- getRowKey,
- } = props
-
- let finnalExpandedRowKeys = []
- let rows = [...data]
-
- if (defaultExpandAllRows) {
- for (let i = 0; i < rows.length; i++) {
- const row = rows[i]
- finnalExpandedRowKeys.push(getRowKey(row, i))
- rows = rows.concat(row[childrenColumnName] || [])
- }
- } else {
- finnalExpandedRowKeys = expandedRowKeys || defaultExpandedRowKeys
- }
-
- this.columnManager = props.columnManager
- this.store = props.store
-
- this.store.setState({
- expandedRowsHeight: {},
- expandedRowKeys: finnalExpandedRowKeys,
- })
- }
-
- componentWillReceiveProps (nextProps) {
- if ('expandedRowKeys' in nextProps) {
- this.store.setState({
- expandedRowKeys: nextProps.expandedRowKeys,
- })
- }
- }
-
- handleExpandChange = (expanded, record, event, rowKey, destroy = false) => {
- if (event) {
- event.preventDefault()
- event.stopPropagation()
- }
-
- const { onExpandedRowsChange, onExpand } = this.props
- let { expandedRowKeys } = this.store.getState()
-
- if (expanded) {
- // row was expaned
- expandedRowKeys = [...expandedRowKeys, rowKey]
- } else {
- // row was collapse
- const expandedRowIndex = expandedRowKeys.indexOf(rowKey)
- if (expandedRowIndex !== -1) {
- expandedRowKeys = remove(expandedRowKeys, rowKey)
- }
- }
-
- if (!this.props.expandedRowKeys) {
- this.store.setState({ expandedRowKeys })
- }
-
- onExpandedRowsChange(expandedRowKeys)
- if (!destroy) {
- onExpand(expanded, record)
- }
- }
-
- renderExpandIndentCell = (rows, fixed) => {
- const { prefixCls, expandIconAsCell } = this.props
- if (!expandIconAsCell || fixed === 'right' || !rows.length) {
- return
- }
-
- const iconColumn = {
- key: 'rc-table-expand-icon-cell',
- className: `${prefixCls}-expand-icon-th`,
- title: '',
- rowSpan: rows.length,
- }
-
- rows[0].unshift({ ...iconColumn, column: iconColumn })
- }
-
- renderExpandedRow (record, index, render, className, ancestorKeys, indent, fixed) {
- const { prefixCls, expandIconAsCell, indentSize } = this.props
- let colCount
- if (fixed === 'left') {
- colCount = this.columnManager.leftLeafColumns().length
- } else if (fixed === 'right') {
- colCount = this.columnManager.rightLeafColumns().length
- } else {
- colCount = this.columnManager.leafColumns().length
- }
- const columns = [{
- key: 'extra-row',
- render: () => ({
- props: {
- colSpan: colCount,
- },
- children: fixed !== 'right' ? render(record, index, indent) : ' ',
- }),
- }]
- if (expandIconAsCell && fixed !== 'right') {
- columns.unshift({
- key: 'expand-icon-placeholder',
- render: () => null,
- })
- }
- const parentKey = ancestorKeys[ancestorKeys.length - 1]
- const rowKey = `${parentKey}-extra-row`
- const components = {
- body: {
- row: 'tr',
- cell: 'td',
- },
- }
-
- return (
-
- )
- }
-
- renderRows = (renderRows, rows, record, index, indent, fixed, parentKey, ancestorKeys) => {
- const { expandedRowClassName, expandedRowRender, childrenColumnName } = this.props
- const childrenData = record[childrenColumnName]
- const nextAncestorKeys = [...ancestorKeys, parentKey]
- const nextIndent = indent + 1
-
- if (expandedRowRender) {
- rows.push(
- this.renderExpandedRow(
- record,
- index,
- expandedRowRender,
- expandedRowClassName(record, index, indent),
- nextAncestorKeys,
- nextIndent,
- fixed,
- ),
- )
- }
-
- if (childrenData) {
- rows.push(
- ...renderRows(
- childrenData,
- nextIndent,
- nextAncestorKeys,
- )
- )
- }
- }
-
- render () {
- const { data, childrenColumnName, children } = this.props
- const needIndentSpaced = data.some(record => record[childrenColumnName])
-
- return children({
- props: this.props,
- needIndentSpaced,
- renderRows: this.renderRows,
- handleExpandChange: this.handleExpandChange,
- renderExpandIndentCell: this.renderExpandIndentCell,
- })
- }
-}
-
-export default connect()(ExpandableTable)
diff --git a/components/vc-table/src/ExpandableTable.jsx b/components/vc-table/src/ExpandableTable.jsx
new file mode 100644
index 000000000..8308699a8
--- /dev/null
+++ b/components/vc-table/src/ExpandableTable.jsx
@@ -0,0 +1,223 @@
+import PropTypes from '../../_util/vue-types'
+import BaseMixin from '../../_util/BaseMixin'
+import { connect } from '../../_util/store'
+import TableRow from './TableRow'
+import { remove } from './utils'
+import { initDefaultProps, getOptionProps } from '../../_util/props-util'
+
+export const ExpandableTableProps = () => ({
+ expandIconAsCell: PropTypes.bool,
+ expandedRowKeys: PropTypes.array,
+ expandedRowClassName: PropTypes.func,
+ defaultExpandAllRows: PropTypes.bool,
+ defaultExpandedRowKeys: PropTypes.array,
+ expandIconColumnIndex: PropTypes.number,
+ expandedRowRender: PropTypes.func,
+ childrenColumnName: PropTypes.string,
+ indentSize: PropTypes.number,
+ // onExpand: PropTypes.func,
+ // onExpandedRowsChange: PropTypes.func,
+ columnManager: PropTypes.object.isRequired,
+ store: PropTypes.object.isRequired,
+ prefixCls: PropTypes.string.isRequired,
+ data: PropTypes.array,
+ getRowKey: PropTypes.func,
+})
+
+const ExpandableTable = {
+ name: 'ExpandableTable',
+ mixins: [BaseMixin],
+ props: initDefaultProps(ExpandableTableProps(), {
+ expandIconAsCell: false,
+ expandedRowClassName: () => '',
+ expandIconColumnIndex: 0,
+ defaultExpandAllRows: false,
+ defaultExpandedRowKeys: [],
+ childrenColumnName: 'children',
+ indentSize: 15,
+ }),
+
+ data () {
+ const {
+ data,
+ childrenColumnName,
+ defaultExpandAllRows,
+ expandedRowKeys,
+ defaultExpandedRowKeys,
+ getRowKey,
+ } = this
+
+ let finnalExpandedRowKeys = []
+ let rows = [...data]
+
+ if (defaultExpandAllRows) {
+ for (let i = 0; i < rows.length; i++) {
+ const row = rows[i]
+ finnalExpandedRowKeys.push(getRowKey(row, i))
+ rows = rows.concat(row[childrenColumnName] || [])
+ }
+ } else {
+ finnalExpandedRowKeys = expandedRowKeys || defaultExpandedRowKeys
+ }
+
+ // this.columnManager = props.columnManager
+ // this.store = props.store
+
+ this.store.setState({
+ expandedRowsHeight: {},
+ expandedRowKeys: finnalExpandedRowKeys,
+ })
+ return {}
+ },
+ watch: {
+ expandedRowKeys (val) {
+ this.store.setState({
+ expandedRowKeys: val,
+ })
+ },
+ },
+ methods: {
+ handleExpandChange (expanded, record, event, rowKey, destroy = false) {
+ if (event) {
+ event.preventDefault()
+ event.stopPropagation()
+ }
+
+ let { expandedRowKeys } = this.store.getState()
+
+ if (expanded) {
+ // row was expaned
+ expandedRowKeys = [...expandedRowKeys, rowKey]
+ } else {
+ // row was collapse
+ const expandedRowIndex = expandedRowKeys.indexOf(rowKey)
+ if (expandedRowIndex !== -1) {
+ expandedRowKeys = remove(expandedRowKeys, rowKey)
+ }
+ }
+
+ if (!this.expandedRowKeys) {
+ this.store.setState({ expandedRowKeys })
+ }
+ this.__emit('expandedRowsChange', expandedRowKeys)
+ if (!destroy) {
+ this.__emit('expand', expanded, record)
+ }
+ },
+
+ renderExpandIndentCell (rows, fixed) {
+ const { prefixCls, expandIconAsCell } = this
+ if (!expandIconAsCell || fixed === 'right' || !rows.length) {
+ return
+ }
+
+ const iconColumn = {
+ key: 'rc-table-expand-icon-cell',
+ className: `${prefixCls}-expand-icon-th`,
+ title: '',
+ rowSpan: rows.length,
+ }
+
+ rows[0].unshift({ ...iconColumn, column: iconColumn })
+ },
+
+ renderExpandedRow (record, index, render, className, ancestorKeys, indent, fixed) {
+ const { prefixCls, expandIconAsCell, indentSize } = this
+ let colCount
+ if (fixed === 'left') {
+ colCount = this.columnManager.leftLeafColumns().length
+ } else if (fixed === 'right') {
+ colCount = this.columnManager.rightLeafColumns().length
+ } else {
+ colCount = this.columnManager.leafColumns().length
+ }
+ const columns = [{
+ key: 'extra-row',
+ render: () => ({
+ props: {
+ colSpan: colCount,
+ },
+ children: fixed !== 'right' ? render(record, index, indent) : ' ',
+ }),
+ }]
+ if (expandIconAsCell && fixed !== 'right') {
+ columns.unshift({
+ key: 'expand-icon-placeholder',
+ render: () => null,
+ })
+ }
+ const parentKey = ancestorKeys[ancestorKeys.length - 1]
+ const rowKey = `${parentKey}-extra-row`
+ const components = {
+ body: {
+ row: 'tr',
+ cell: 'td',
+ },
+ }
+
+ return (
+
+ )
+ },
+
+ renderRows (renderRows, rows, record, index, indent, fixed, parentKey, ancestorKeys) {
+ const { expandedRowClassName, expandedRowRender, childrenColumnName } = this
+ const childrenData = record[childrenColumnName]
+ const nextAncestorKeys = [...ancestorKeys, parentKey]
+ const nextIndent = indent + 1
+
+ if (expandedRowRender) {
+ rows.push(
+ this.renderExpandedRow(
+ record,
+ index,
+ expandedRowRender,
+ expandedRowClassName(record, index, indent),
+ nextAncestorKeys,
+ nextIndent,
+ fixed,
+ ),
+ )
+ }
+
+ if (childrenData) {
+ rows.push(
+ ...renderRows(
+ childrenData,
+ nextIndent,
+ nextAncestorKeys,
+ )
+ )
+ }
+ },
+ },
+
+ render () {
+ const { data, childrenColumnName, $scopedSlots, $listeners } = this
+ const props = getOptionProps(this)
+ const needIndentSpaced = data.some(record => record[childrenColumnName])
+
+ return $scopedSlots.default && $scopedSlots.default({
+ props,
+ on: $listeners,
+ needIndentSpaced,
+ renderRows: this.renderRows,
+ handleExpandChange: this.handleExpandChange,
+ renderExpandIndentCell: this.renderExpandIndentCell,
+ })
+ },
+}
+
+export default connect()(ExpandableTable)
diff --git a/components/vc-table/src/HeadTable.jsx b/components/vc-table/src/HeadTable.jsx
index e2095b364..99c6468f0 100644
--- a/components/vc-table/src/HeadTable.jsx
+++ b/components/vc-table/src/HeadTable.jsx
@@ -14,6 +14,9 @@ export default {
handleBodyScrollLeft: PropTypes.func.isRequired,
expander: PropTypes.object.isRequired,
},
+ inject: {
+ table: { default: {}},
+ },
render () {
const { columns, fixed, tableClassName, handleBodyScrollLeft, expander, table } = this
const { prefixCls, scroll, showHeader } = table
diff --git a/components/vc-table/src/Table.js b/components/vc-table/src/Table.js
deleted file mode 100644
index 566e522de..000000000
--- a/components/vc-table/src/Table.js
+++ /dev/null
@@ -1,475 +0,0 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import { debounce, warningOnce } from './utils'
-import shallowequal from 'shallowequal'
-import addEventListener from 'rc-util/lib/Dom/addEventListener'
-import { Provider, create } from 'mini-store'
-import merge from 'lodash/merge'
-import ColumnManager from './ColumnManager'
-import classes from 'component-classes'
-import HeadTable from './HeadTable'
-import BodyTable from './BodyTable'
-import ExpandableTable from './ExpandableTable'
-
-export default class Table extends React.Component {
- static propTypes = {
- data: PropTypes.array,
- useFixedHeader: PropTypes.bool,
- columns: PropTypes.array,
- prefixCls: PropTypes.string,
- bodyStyle: PropTypes.object,
- style: PropTypes.object,
- rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
- rowClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
- onRow: PropTypes.func,
- onHeaderRow: PropTypes.func,
- onRowClick: PropTypes.func,
- onRowDoubleClick: PropTypes.func,
- onRowContextMenu: PropTypes.func,
- onRowMouseEnter: PropTypes.func,
- onRowMouseLeave: PropTypes.func,
- showHeader: PropTypes.bool,
- title: PropTypes.func,
- id: PropTypes.string,
- footer: PropTypes.func,
- emptyText: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
- scroll: PropTypes.object,
- rowRef: PropTypes.func,
- getBodyWrapper: PropTypes.func,
- children: PropTypes.node,
- components: PropTypes.shape({
- table: PropTypes.any,
- header: PropTypes.shape({
- wrapper: PropTypes.any,
- row: PropTypes.any,
- cell: PropTypes.any,
- }),
- body: PropTypes.shape({
- wrapper: PropTypes.any,
- row: PropTypes.any,
- cell: PropTypes.any,
- }),
- }),
- ...ExpandableTable.PropTypes,
- }
-
- static childContextTypes = {
- table: PropTypes.any,
- components: PropTypes.any,
- }
-
- static defaultProps = {
- data: [],
- useFixedHeader: false,
- rowKey: 'key',
- rowClassName: () => '',
- onRow () {},
- onHeaderRow () {},
- prefixCls: 'rc-table',
- bodyStyle: {},
- style: {},
- showHeader: true,
- scroll: {},
- rowRef: () => null,
- emptyText: () => 'No Data',
- }
-
- constructor (props) {
- super(props);
-
- [
- 'onRowClick',
- 'onRowDoubleClick',
- 'onRowContextMenu',
- 'onRowMouseEnter',
- 'onRowMouseLeave',
- ].forEach(name => {
- warningOnce(
- props[name] === undefined,
- `${name} is deprecated, please use onRow instead.`,
- )
- })
-
- warningOnce(
- props.getBodyWrapper === undefined,
- 'getBodyWrapper is deprecated, please use custom components instead.',
- )
-
- this.columnManager = new ColumnManager(props.columns, props.children)
-
- this.store = create({
- currentHoverKey: null,
- fixedColumnsHeadRowsHeight: [],
- fixedColumnsBodyRowsHeight: [],
- })
-
- this.setScrollPosition('left')
-
- this.debouncedWindowResize = debounce(this.handleWindowResize, 150)
- }
-
- getChildContext () {
- return {
- table: {
- props: this.props,
- columnManager: this.columnManager,
- saveRef: this.saveRef,
- components: merge({
- table: 'table',
- header: {
- wrapper: 'thead',
- row: 'tr',
- cell: 'th',
- },
- body: {
- wrapper: 'tbody',
- row: 'tr',
- cell: 'td',
- },
- }, this.props.components),
- },
- }
- }
-
- componentDidMount () {
- if (this.columnManager.isAnyColumnsFixed()) {
- this.handleWindowResize()
- this.resizeEvent = addEventListener(
- window, 'resize', this.debouncedWindowResize
- )
- }
- }
-
- componentWillReceiveProps (nextProps) {
- if (nextProps.columns && nextProps.columns !== this.props.columns) {
- this.columnManager.reset(nextProps.columns)
- } else if (nextProps.children !== this.props.children) {
- this.columnManager.reset(null, nextProps.children)
- }
- }
-
- componentDidUpdate (prevProps) {
- if (this.columnManager.isAnyColumnsFixed()) {
- this.handleWindowResize()
- if (!this.resizeEvent) {
- this.resizeEvent = addEventListener(
- window, 'resize', this.debouncedWindowResize
- )
- }
- }
- // when table changes to empty, reset scrollLeft
- if (prevProps.data.length > 0 && this.props.data.length === 0 && this.hasScrollX()) {
- this.resetScrollX()
- }
- }
-
- componentWillUnmount () {
- if (this.resizeEvent) {
- this.resizeEvent.remove()
- }
- if (this.debouncedWindowResize) {
- this.debouncedWindowResize.cancel()
- }
- }
-
- getRowKey = (record, index) => {
- const rowKey = this.props.rowKey
- const key = (typeof rowKey === 'function')
- ? rowKey(record, index) : record[rowKey]
- warningOnce(
- key !== undefined,
- 'Each record in table should have a unique `key` prop,' +
- 'or set `rowKey` to an unique primary key.'
- )
- return key === undefined ? index : key
- }
-
- setScrollPosition (position) {
- this.scrollPosition = position
- if (this.tableNode) {
- const { prefixCls } = this.props
- if (position === 'both') {
- classes(this.tableNode)
- .remove(new RegExp(`^${prefixCls}-scroll-position-.+$`))
- .add(`${prefixCls}-scroll-position-left`)
- .add(`${prefixCls}-scroll-position-right`)
- } else {
- classes(this.tableNode)
- .remove(new RegExp(`^${prefixCls}-scroll-position-.+$`))
- .add(`${prefixCls}-scroll-position-${position}`)
- }
- }
- }
-
- setScrollPositionClassName () {
- const node = this.bodyTable
- const scrollToLeft = node.scrollLeft === 0
- const scrollToRight = node.scrollLeft + 1 >=
- node.children[0].getBoundingClientRect().width -
- node.getBoundingClientRect().width
- if (scrollToLeft && scrollToRight) {
- this.setScrollPosition('both')
- } else if (scrollToLeft) {
- this.setScrollPosition('left')
- } else if (scrollToRight) {
- this.setScrollPosition('right')
- } else if (this.scrollPosition !== 'middle') {
- this.setScrollPosition('middle')
- }
- }
-
- handleWindowResize = () => {
- this.syncFixedTableRowHeight()
- this.setScrollPositionClassName()
- }
-
- syncFixedTableRowHeight = () => {
- const tableRect = this.tableNode.getBoundingClientRect()
- // If tableNode's height less than 0, suppose it is hidden and don't recalculate rowHeight.
- // see: https://github.com/ant-design/ant-design/issues/4836
- if (tableRect.height !== undefined && tableRect.height <= 0) {
- return
- }
- const { prefixCls } = this.props
- const headRows = this.headTable
- ? this.headTable.querySelectorAll('thead')
- : this.bodyTable.querySelectorAll('thead')
- const bodyRows = this.bodyTable.querySelectorAll(`.${prefixCls}-row`) || []
- const fixedColumnsHeadRowsHeight = [].map.call(
- headRows, row => row.getBoundingClientRect().height || 'auto'
- )
- const fixedColumnsBodyRowsHeight = [].map.call(
- bodyRows, row => row.getBoundingClientRect().height || 'auto'
- )
- const state = this.store.getState()
- if (shallowequal(state.fixedColumnsHeadRowsHeight, fixedColumnsHeadRowsHeight) &&
- shallowequal(state.fixedColumnsBodyRowsHeight, fixedColumnsBodyRowsHeight)) {
- return
- }
-
- this.store.setState({
- fixedColumnsHeadRowsHeight,
- fixedColumnsBodyRowsHeight,
- })
- }
-
- resetScrollX () {
- if (this.headTable) {
- this.headTable.scrollLeft = 0
- }
- if (this.bodyTable) {
- this.bodyTable.scrollLeft = 0
- }
- }
-
- hasScrollX () {
- const { scroll = {}} = this.props
- return 'x' in scroll
- }
-
- handleBodyScrollLeft = (e) => {
- // Fix https://github.com/ant-design/ant-design/issues/7635
- if (e.currentTarget !== e.target) {
- return
- }
- const target = e.target
- const { scroll = {}} = this.props
- const { headTable, bodyTable } = this
- if (target.scrollLeft !== this.lastScrollLeft && scroll.x) {
- if (target === bodyTable && headTable) {
- headTable.scrollLeft = target.scrollLeft
- } else if (target === headTable && bodyTable) {
- bodyTable.scrollLeft = target.scrollLeft
- }
- this.setScrollPositionClassName()
- }
- // Remember last scrollLeft for scroll direction detecting.
- this.lastScrollLeft = target.scrollLeft
- }
-
- handleBodyScrollTop = (e) => {
- const target = e.target
- const { scroll = {}} = this.props
- const { headTable, bodyTable, fixedColumnsBodyLeft, fixedColumnsBodyRight } = this
- if (target.scrollTop !== this.lastScrollTop && scroll.y && target !== headTable) {
- const scrollTop = target.scrollTop
- if (fixedColumnsBodyLeft && target !== fixedColumnsBodyLeft) {
- fixedColumnsBodyLeft.scrollTop = scrollTop
- }
- if (fixedColumnsBodyRight && target !== fixedColumnsBodyRight) {
- fixedColumnsBodyRight.scrollTop = scrollTop
- }
- if (bodyTable && target !== bodyTable) {
- bodyTable.scrollTop = scrollTop
- }
- }
- // Remember last scrollTop for scroll direction detecting.
- this.lastScrollTop = target.scrollTop
- }
-
- handleBodyScroll = (e) => {
- this.handleBodyScrollLeft(e)
- this.handleBodyScrollTop(e)
- }
-
- saveRef = (name) => (node) => {
- this[name] = node
- }
-
- renderMainTable () {
- const { scroll, prefixCls } = this.props
- const isAnyColumnsFixed = this.columnManager.isAnyColumnsFixed()
- const scrollable = isAnyColumnsFixed || scroll.x || scroll.y
-
- const table = [
- this.renderTable({
- columns: this.columnManager.groupedColumns(),
- isAnyColumnsFixed,
- }),
- this.renderEmptyText(),
- this.renderFooter(),
- ]
-
- return scrollable ? (
- {table}
- ) : table
- }
-
- renderLeftFixedTable () {
- const { prefixCls } = this.props
-
- return (
-
- {this.renderTable({
- columns: this.columnManager.leftColumns(),
- fixed: 'left',
- })}
-
- )
- }
-
- renderRightFixedTable () {
- const { prefixCls } = this.props
-
- return (
-
- {this.renderTable({
- columns: this.columnManager.rightColumns(),
- fixed: 'right',
- })}
-
- )
- }
-
- renderTable (options) {
- const { columns, fixed, isAnyColumnsFixed } = options
- const { prefixCls, scroll = {}} = this.props
- const tableClassName = (scroll.x || fixed) ? `${prefixCls}-fixed` : ''
-
- const headTable = (
-
- )
-
- const bodyTable = (
-
- )
-
- return [headTable, bodyTable]
- }
-
- renderTitle () {
- const { title, prefixCls } = this.props
- return title ? (
-
- {title(this.props.data)}
-
- ) : null
- }
-
- renderFooter () {
- const { footer, prefixCls } = this.props
- return footer ? (
-
- {footer(this.props.data)}
-
- ) : null
- }
-
- renderEmptyText () {
- const { emptyText, prefixCls, data } = this.props
- if (data.length) {
- return null
- }
- const emptyClassName = `${prefixCls}-placeholder`
- return (
-
- {(typeof emptyText === 'function') ? emptyText() : emptyText}
-
- )
- }
-
- render () {
- const props = this.props
- const prefixCls = props.prefixCls
-
- let className = props.prefixCls
- if (props.className) {
- className += ` ${props.className}`
- }
- if (props.useFixedHeader || (props.scroll && props.scroll.y)) {
- className += ` ${prefixCls}-fixed-header`
- }
- if (this.scrollPosition === 'both') {
- className += ` ${prefixCls}-scroll-position-left ${prefixCls}-scroll-position-right`
- } else {
- className += ` ${prefixCls}-scroll-position-${this.scrollPosition}`
- }
- const hasLeftFixed = this.columnManager.isAnyColumnsLeftFixed()
- const hasRightFixed = this.columnManager.isAnyColumnsRightFixed()
-
- return (
-
-
- {(expander) => {
- this.expander = expander
- return (
-
- {this.renderTitle()}
-
- {this.renderMainTable()}
- {hasLeftFixed && this.renderLeftFixedTable()}
- {hasRightFixed && this.renderRightFixedTable()}
-
-
- )
- }}
-
-
- )
- }
-}
diff --git a/components/vc-table/src/Table.jsx b/components/vc-table/src/Table.jsx
new file mode 100644
index 000000000..84217873a
--- /dev/null
+++ b/components/vc-table/src/Table.jsx
@@ -0,0 +1,507 @@
+
+import PropTypes from '../../_util/vue-types'
+import { debounce, warningOnce } from './utils'
+import shallowequal from 'shallowequal'
+import addEventListener from '../../_util/Dom/addEventListener'
+import { Provider, create } from '../../_util/store'
+import merge from 'lodash/merge'
+import ColumnManager from './ColumnManager'
+import classes from 'component-classes'
+import HeadTable from './HeadTable'
+import BodyTable from './BodyTable'
+import ExpandableTable from './ExpandableTable'
+import { initDefaultProps, getOptionProps } from '../../_util/props-util'
+import BaseMixin from '../../_util/BaseMixin'
+
+export default {
+ name: 'Table',
+ mixins: [BaseMixin],
+ props: initDefaultProps({
+ data: PropTypes.array,
+ useFixedHeader: PropTypes.bool,
+ columns: PropTypes.array,
+ prefixCls: PropTypes.string,
+ bodyStyle: PropTypes.object,
+ rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
+ rowClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
+ // onRow: PropTypes.func,
+ // onHeaderRow: PropTypes.func,
+ // onRowClick: PropTypes.func,
+ // onRowDoubleClick: PropTypes.func,
+ // onRowContextMenu: PropTypes.func,
+ // onRowMouseEnter: PropTypes.func,
+ // onRowMouseLeave: PropTypes.func,
+ showHeader: PropTypes.bool,
+ title: PropTypes.func,
+ id: PropTypes.string,
+ footer: PropTypes.func,
+ emptyText: PropTypes.any,
+ scroll: PropTypes.object,
+ rowRef: PropTypes.func,
+ getBodyWrapper: PropTypes.func,
+ components: PropTypes.shape({
+ table: PropTypes.any,
+ header: PropTypes.shape({
+ wrapper: PropTypes.any,
+ row: PropTypes.any,
+ cell: PropTypes.any,
+ }),
+ body: PropTypes.shape({
+ wrapper: PropTypes.any,
+ row: PropTypes.any,
+ cell: PropTypes.any,
+ }),
+ }),
+ expandIconAsCell: PropTypes.bool,
+ expandedRowKeys: PropTypes.array,
+ expandedRowClassName: PropTypes.func,
+ defaultExpandAllRows: PropTypes.bool,
+ defaultExpandedRowKeys: PropTypes.array,
+ expandIconColumnIndex: PropTypes.number,
+ expandedRowRender: PropTypes.func,
+ childrenColumnName: PropTypes.string,
+ indentSize: PropTypes.number,
+ }, {
+ data: [],
+ useFixedHeader: false,
+ rowKey: 'key',
+ rowClassName: () => '',
+ prefixCls: 'rc-table',
+ bodyStyle: {},
+ showHeader: true,
+ scroll: {},
+ rowRef: () => null,
+ emptyText: () => 'No Data',
+ }),
+
+ // static childContextTypes = {
+ // table: PropTypes.any,
+ // components: PropTypes.any,
+ // },
+
+ created () {
+ [
+ 'rowClick',
+ 'rowDoubleclick',
+ 'rowContextmenu',
+ 'rowMouseenter',
+ 'rowMouseleave',
+ ].forEach(name => {
+ warningOnce(
+ this.$listeners[name] === undefined,
+ `${name} is deprecated, please use onRow instead.`,
+ )
+ })
+
+ warningOnce(
+ this.getBodyWrapper === undefined,
+ 'getBodyWrapper is deprecated, please use custom components instead.',
+ )
+
+ // this.columnManager = new ColumnManager(this.columns, this.$slots.default)
+
+ this.store = create({
+ currentHoverKey: null,
+ fixedColumnsHeadRowsHeight: [],
+ fixedColumnsBodyRowsHeight: [],
+ })
+
+ this.setScrollPosition('left')
+
+ this.debouncedWindowResize = debounce(this.handleWindowResize, 150)
+ },
+ data () {
+ this.preData = [...this.data]
+ return {
+ columnManager: new ColumnManager(this.columns, this.$slots.default),
+ sComponents: merge({
+ table: 'table',
+ header: {
+ wrapper: 'thead',
+ row: 'tr',
+ cell: 'th',
+ },
+ body: {
+ wrapper: 'tbody',
+ row: 'tr',
+ cell: 'td',
+ },
+ }, this.components),
+ }
+ },
+ provide () {
+ return {
+ table: this,
+ }
+ },
+ watch: {
+ components (val) {
+ this._components = merge({
+ table: 'table',
+ header: {
+ wrapper: 'thead',
+ row: 'tr',
+ cell: 'th',
+ },
+ body: {
+ wrapper: 'tbody',
+ row: 'tr',
+ cell: 'td',
+ },
+ }, this.components)
+ },
+ columns (val) {
+ if (val) {
+ this.columnManager.reset(val)
+ }
+ },
+ data (val) {
+ if (val.length === 0 && this.hasScrollX()) {
+ this.$nextTick(() => {
+ this.resetScrollX()
+ })
+ }
+ },
+ },
+
+ mounted () {
+ this.$nextTick(() => {
+ if (this.columnManager.isAnyColumnsFixed()) {
+ this.handleWindowResize()
+ this.resizeEvent = addEventListener(
+ window, 'resize', this.debouncedWindowResize
+ )
+ }
+ })
+ },
+
+ componentWillReceiveProps (nextProps) {
+ if (nextProps.columns && nextProps.columns !== this.props.columns) {
+ this.columnManager.reset(nextProps.columns)
+ } else if (nextProps.children !== this.props.children) {
+ this.columnManager.reset(null, nextProps.children)
+ }
+ },
+
+ updated (prevProps) {
+ if (this.columnManager.isAnyColumnsFixed()) {
+ this.handleWindowResize()
+ if (!this.resizeEvent) {
+ this.resizeEvent = addEventListener(
+ window, 'resize', this.debouncedWindowResize
+ )
+ }
+ }
+ },
+
+ beforeDestroy () {
+ if (this.resizeEvent) {
+ this.resizeEvent.remove()
+ }
+ if (this.debouncedWindowResize) {
+ this.debouncedWindowResize.cancel()
+ }
+ },
+ methods: {
+ getRowKey (record, index) {
+ const rowKey = this.rowKey
+ const key = (typeof rowKey === 'function')
+ ? rowKey(record, index) : record[rowKey]
+ warningOnce(
+ key !== undefined,
+ 'Each record in table should have a unique `key` prop,' +
+ 'or set `rowKey` to an unique primary key.'
+ )
+ return key === undefined ? index : key
+ },
+
+ setScrollPosition (position) {
+ this.scrollPosition = position
+ if (this.tableNode) {
+ const { prefixCls } = this
+ if (position === 'both') {
+ classes(this.tableNode)
+ .remove(new RegExp(`^${prefixCls}-scroll-position-.+$`))
+ .add(`${prefixCls}-scroll-position-left`)
+ .add(`${prefixCls}-scroll-position-right`)
+ } else {
+ classes(this.tableNode)
+ .remove(new RegExp(`^${prefixCls}-scroll-position-.+$`))
+ .add(`${prefixCls}-scroll-position-${position}`)
+ }
+ }
+ },
+
+ setScrollPositionClassName () {
+ const node = this.bodyTable
+ const scrollToLeft = node.scrollLeft === 0
+ const scrollToRight = node.scrollLeft + 1 >=
+ node.children[0].getBoundingClientRect().width -
+ node.getBoundingClientRect().width
+ if (scrollToLeft && scrollToRight) {
+ this.setScrollPosition('both')
+ } else if (scrollToLeft) {
+ this.setScrollPosition('left')
+ } else if (scrollToRight) {
+ this.setScrollPosition('right')
+ } else if (this.scrollPosition !== 'middle') {
+ this.setScrollPosition('middle')
+ }
+ },
+
+ handleWindowResize () {
+ this.syncFixedTableRowHeight()
+ this.setScrollPositionClassName()
+ },
+
+ syncFixedTableRowHeight () {
+ const tableRect = this.tableNode.getBoundingClientRect()
+ // If tableNode's height less than 0, suppose it is hidden and don't recalculate rowHeight.
+ // see: https://github.com/ant-design/ant-design/issues/4836
+ if (tableRect.height !== undefined && tableRect.height <= 0) {
+ return
+ }
+ const { prefixCls } = this.props
+ const headRows = this.headTable
+ ? this.headTable.querySelectorAll('thead')
+ : this.bodyTable.querySelectorAll('thead')
+ const bodyRows = this.bodyTable.querySelectorAll(`.${prefixCls}-row`) || []
+ const fixedColumnsHeadRowsHeight = [].map.call(
+ headRows, row => row.getBoundingClientRect().height || 'auto'
+ )
+ const fixedColumnsBodyRowsHeight = [].map.call(
+ bodyRows, row => row.getBoundingClientRect().height || 'auto'
+ )
+ const state = this.store.getState()
+ if (shallowequal(state.fixedColumnsHeadRowsHeight, fixedColumnsHeadRowsHeight) &&
+ shallowequal(state.fixedColumnsBodyRowsHeight, fixedColumnsBodyRowsHeight)) {
+ return
+ }
+
+ this.store.setState({
+ fixedColumnsHeadRowsHeight,
+ fixedColumnsBodyRowsHeight,
+ })
+ },
+
+ resetScrollX () {
+ if (this.headTable) {
+ this.headTable.scrollLeft = 0
+ }
+ if (this.bodyTable) {
+ this.bodyTable.scrollLeft = 0
+ }
+ },
+
+ hasScrollX () {
+ const { scroll = {}} = this
+ return 'x' in scroll
+ },
+
+ handleBodyScrollLeft (e) {
+ // Fix https://github.com/ant-design/ant-design/issues/7635
+ if (e.currentTarget !== e.target) {
+ return
+ }
+ const target = e.target
+ const { scroll = {}} = this
+ const { headTable, bodyTable } = this
+ if (target.scrollLeft !== this.lastScrollLeft && scroll.x) {
+ if (target === bodyTable && headTable) {
+ headTable.scrollLeft = target.scrollLeft
+ } else if (target === headTable && bodyTable) {
+ bodyTable.scrollLeft = target.scrollLeft
+ }
+ this.setScrollPositionClassName()
+ }
+ // Remember last scrollLeft for scroll direction detecting.
+ this.lastScrollLeft = target.scrollLeft
+ },
+
+ handleBodyScrollTop (e) {
+ const target = e.target
+ const { scroll = {}} = this
+ const { headTable, bodyTable, fixedColumnsBodyLeft, fixedColumnsBodyRight } = this
+ if (target.scrollTop !== this.lastScrollTop && scroll.y && target !== headTable) {
+ const scrollTop = target.scrollTop
+ if (fixedColumnsBodyLeft && target !== fixedColumnsBodyLeft) {
+ fixedColumnsBodyLeft.scrollTop = scrollTop
+ }
+ if (fixedColumnsBodyRight && target !== fixedColumnsBodyRight) {
+ fixedColumnsBodyRight.scrollTop = scrollTop
+ }
+ if (bodyTable && target !== bodyTable) {
+ bodyTable.scrollTop = scrollTop
+ }
+ }
+ // Remember last scrollTop for scroll direction detecting.
+ this.lastScrollTop = target.scrollTop
+ },
+
+ handleBodyScroll (e) {
+ this.handleBodyScrollLeft(e)
+ this.handleBodyScrollTop(e)
+ },
+
+ renderMainTable () {
+ const { scroll, prefixCls } = this
+ const isAnyColumnsFixed = this.columnManager.isAnyColumnsFixed()
+ const scrollable = isAnyColumnsFixed || scroll.x || scroll.y
+
+ const table = [
+ this.renderTable({
+ columns: this.columnManager.groupedColumns(),
+ isAnyColumnsFixed,
+ }),
+ this.renderEmptyText(),
+ this.renderFooter(),
+ ]
+
+ return scrollable ? (
+ {table}
+ ) : table
+ },
+
+ renderLeftFixedTable () {
+ const { prefixCls } = this
+
+ return (
+
+ {this.renderTable({
+ columns: this.columnManager.leftColumns(),
+ fixed: 'left',
+ })}
+
+ )
+ },
+ renderRightFixedTable () {
+ const { prefixCls } = this
+
+ return (
+
+ {this.renderTable({
+ columns: this.columnManager.rightColumns(),
+ fixed: 'right',
+ })}
+
+ )
+ },
+
+ renderTable (options) {
+ const { columns, fixed, isAnyColumnsFixed } = options
+ const { prefixCls, scroll = {}} = this
+ const tableClassName = (scroll.x || fixed) ? `${prefixCls}-fixed` : ''
+
+ const headTable = (
+
+ )
+
+ const bodyTable = (
+
+ )
+
+ return [headTable, bodyTable]
+ },
+
+ renderTitle () {
+ const { title, prefixCls } = this
+ return title ? (
+
+ {title(this.props.data)}
+
+ ) : null
+ },
+
+ renderFooter () {
+ const { footer, prefixCls } = this
+ return footer ? (
+
+ ) : null
+ },
+
+ renderEmptyText () {
+ const { emptyText, prefixCls, data } = this
+ if (data.length) {
+ return null
+ }
+ const emptyClassName = `${prefixCls}-placeholder`
+ return (
+
+ {(typeof emptyText === 'function') ? emptyText() : emptyText}
+
+ )
+ },
+ },
+
+ render () {
+ const props = getOptionProps(this)
+ const { $listeners, columnManager, getRowKey } = this
+ const prefixCls = props.prefixCls
+
+ let className = props.prefixCls
+ if (props.useFixedHeader || (props.scroll && props.scroll.y)) {
+ className += ` ${prefixCls}-fixed-header`
+ }
+ if (this.scrollPosition === 'both') {
+ className += ` ${prefixCls}-scroll-position-left ${prefixCls}-scroll-position-right`
+ } else {
+ className += ` ${prefixCls}-scroll-position-${this.scrollPosition}`
+ }
+ const hasLeftFixed = columnManager.isAnyColumnsLeftFixed()
+ const hasRightFixed = columnManager.isAnyColumnsRightFixed()
+
+ const expandableTableProps = {
+ props: {
+ ...props,
+ columnManager,
+ getRowKey,
+ },
+ on: { ...$listeners },
+ scopedSlots: {
+ default: (expander) => {
+ this.expander = expander
+ return (
+
+ {this.renderTitle()}
+
+ {this.renderMainTable()}
+ {hasLeftFixed && this.renderLeftFixedTable()}
+ {hasRightFixed && this.renderRightFixedTable()}
+
+
+ )
+ },
+ },
+ }
+ return (
+
+
+
+ )
+ },
+}
diff --git a/components/vc-table/src/TableCell.jsx b/components/vc-table/src/TableCell.jsx
index 41bccae5e..526f40ce9 100644
--- a/components/vc-table/src/TableCell.jsx
+++ b/components/vc-table/src/TableCell.jsx
@@ -10,12 +10,12 @@ export default {
indent: PropTypes.number,
indentSize: PropTypes.number,
column: PropTypes.object,
- expandIcon: PropTypes.node,
+ expandIcon: PropTypes.any,
component: PropTypes.any,
},
methods: {
isInvalidRenderCellText (text) {
- debugger
+ // debugger
return text &&
Object.prototype.toString.call(text) === '[object Object]'
},
diff --git a/components/vc-table/src/TableHeader.jsx b/components/vc-table/src/TableHeader.jsx
index b0a1be40f..9e6271b8e 100644
--- a/components/vc-table/src/TableHeader.jsx
+++ b/components/vc-table/src/TableHeader.jsx
@@ -41,6 +41,9 @@ export default {
expander: PropTypes.object.isRequired,
},
+ inject: {
+ table: { default: {}},
+ },
methods: {
onHeaderRow () {
this.table.__emit('headerRow', ...arguments)
@@ -48,7 +51,7 @@ export default {
},
render () {
- const { components, prefixCls, showHeader } = this.table
+ const { sComponents: components, prefixCls, showHeader } = this.table
const { expander, columns, fixed, onHeaderRow } = this
if (!showHeader) {
diff --git a/components/vc-table/src/TableHeaderRow.js b/components/vc-table/src/TableHeaderRow.js
deleted file mode 100644
index d801ba46d..000000000
--- a/components/vc-table/src/TableHeaderRow.js
+++ /dev/null
@@ -1,53 +0,0 @@
-import React from 'react'
-import { connect } from 'mini-store'
-
-function TableHeaderRow ({ row, index, height, components, onHeaderRow }) {
- const HeaderRow = components.header.row
- const HeaderCell = components.header.cell
- const rowProps = onHeaderRow(row.map(cell => cell.column), index)
- const customStyle = rowProps ? rowProps.style : {}
- const style = { height, ...customStyle }
-
- return (
-
- {row.map((cell, i) => {
- const { column, ...cellProps } = cell
- const customProps = column.onHeaderCell ? column.onHeaderCell(column) : {}
- if (column.align) {
- cellProps.style = { textAlign: column.align }
- }
- return (
-
- )
- })}
-
- )
-}
-
-function getRowHeight (state, props) {
- const { fixedColumnsHeadRowsHeight } = state
- const { columns, rows, fixed } = props
- const headerHeight = fixedColumnsHeadRowsHeight[0]
-
- if (!fixed) {
- return null
- }
-
- if (headerHeight && columns) {
- if (headerHeight === 'auto') {
- return 'auto'
- }
- return headerHeight / rows.length
- }
- return null
-}
-
-export default connect((state, props) => {
- return {
- height: getRowHeight(state, props),
- }
-})(TableHeaderRow)
diff --git a/components/vc-table/src/TableHeaderRow.jsx b/components/vc-table/src/TableHeaderRow.jsx
new file mode 100644
index 000000000..6e23182a1
--- /dev/null
+++ b/components/vc-table/src/TableHeaderRow.jsx
@@ -0,0 +1,71 @@
+import PropTypes from '../../_util/vue-types'
+import { connect } from '../../_util/store'
+
+const TableHeaderRow = {
+ props: {
+ index: PropTypes.number,
+ fixed: PropTypes.string,
+ columns: PropTypes.array,
+ rows: PropTypes.array,
+ row: PropTypes.array,
+ components: PropTypes.object,
+ height: PropTypes.any,
+ },
+ name: 'TableHeaderRow',
+ render () {
+ const { row, index, height, components, $listeners = {}} = this
+ const onHeaderRow = $listeners.headerRow
+ const HeaderRow = components.header.row
+ const HeaderCell = components.header.cell
+ const rowProps = onHeaderRow(row.map(cell => cell.column), index)
+ const customStyle = rowProps ? rowProps.style : {}
+ const style = { height, ...customStyle }
+
+ return (
+
+ {row.map((cell, i) => {
+ const { column, children, className, ...cellProps } = cell
+ const customProps = column.onHeaderCell ? column.onHeaderCell(column) : {}
+ if (column.align) {
+ cellProps.style = { textAlign: column.align }
+ }
+
+ return (
+
+ {children}
+
+ )
+ })}
+
+ )
+ },
+}
+
+function getRowHeight (state, props) {
+ const { fixedColumnsHeadRowsHeight } = state
+ const { columns, rows, fixed } = props
+ const headerHeight = fixedColumnsHeadRowsHeight[0]
+
+ if (!fixed) {
+ return null
+ }
+
+ if (headerHeight && columns) {
+ if (headerHeight === 'auto') {
+ return 'auto'
+ }
+ return `${headerHeight / rows.length}px`
+ }
+ return null
+}
+
+export default connect((state, props) => {
+ return {
+ height: getRowHeight(state, props),
+ }
+})(TableHeaderRow)
diff --git a/components/vc-table/src/TableRow.js b/components/vc-table/src/TableRow.jsx
similarity index 52%
rename from components/vc-table/src/TableRow.js
rename to components/vc-table/src/TableRow.jsx
index 3348bb559..1ea693648 100644
--- a/components/vc-table/src/TableRow.js
+++ b/components/vc-table/src/TableRow.jsx
@@ -1,21 +1,23 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import PropTypes from 'prop-types'
-import { connect } from 'mini-store'
+import PropTypes from '../../_util/vue-types'
+import { connect } from '../../_util/store'
import TableCell from './TableCell'
import { warningOnce } from './utils'
+import { initDefaultProps } from '../../_util/props-util'
+import BaseMixin from '../../_util/BaseMixin'
-class TableRow extends React.Component {
- static propTypes = {
- onRow: PropTypes.func,
- onRowClick: PropTypes.func,
- onRowDoubleClick: PropTypes.func,
- onRowContextMenu: PropTypes.func,
- onRowMouseEnter: PropTypes.func,
- onRowMouseLeave: PropTypes.func,
+const TableRow = {
+ name: 'TableRow',
+ mixins: [BaseMixin],
+ props: initDefaultProps({
+ // onRow: PropTypes.func,
+ // onRowClick: PropTypes.func,
+ // onRowDoubleClick: PropTypes.func,
+ // onRowContextMenu: PropTypes.func,
+ // onRowMouseEnter: PropTypes.func,
+ // onRowMouseLeave: PropTypes.func,
record: PropTypes.object,
prefixCls: PropTypes.string,
- onHover: PropTypes.func,
+ // onHover: PropTypes.func,
columns: PropTypes.array,
height: PropTypes.oneOfType([
PropTypes.string,
@@ -43,133 +45,131 @@ class TableRow extends React.Component {
expandedRow: PropTypes.bool,
isAnyColumnsFixed: PropTypes.bool,
ancestorKeys: PropTypes.array.isRequired,
- }
-
- static defaultProps = {
- onRow () {},
+ expandIconColumnIndex: PropTypes.number,
+ expandRowByClick: PropTypes.bool,
+ // visible: PropTypes.bool,
+ // hovered: PropTypes.bool,
+ // height: PropTypes.any,
+ }, {
expandIconColumnIndex: 0,
expandRowByClick: false,
- onHover () {},
hasExpandIcon () {},
renderExpandIcon () {},
renderExpandIconCell () {},
- }
+ }),
- constructor (props) {
- super(props)
+ data () {
+ this.shouldRender = this.visible
+ return {}
+ },
- this.shouldRender = props.visible
- }
-
- componentDidMount () {
+ mounted () {
if (this.shouldRender) {
- this.saveRowRef()
+ this.$nextTick(() => {
+ this.saveRowRef()
+ })
}
- }
+ },
+ watch: {
+
+ },
componentWillReceiveProps (nextProps) {
if (this.props.visible || (!this.props.visible && nextProps.visible)) {
this.shouldRender = true
}
- }
+ },
shouldComponentUpdate (nextProps) {
return !!(this.props.visible || nextProps.visible)
- }
+ },
- componentDidUpdate () {
+ updated () {
if (this.shouldRender && !this.rowRef) {
- this.saveRowRef()
+ this.$nextTick(() => {
+ this.saveRowRef()
+ })
}
- }
+ },
+ methods: {
+ onRowClick (event) {
+ const { record, index } = this
+ this.__emit('rowClick', record, index, event)
+ },
- onRowClick = (event) => {
- const { record, index, onRowClick } = this.props
- if (onRowClick) {
- onRowClick(record, index, event)
- }
- }
+ onRowDoubleClick (event) {
+ const { record, index } = this
+ this.__emit('rowDoubleClick', record, index, event)
+ },
- onRowDoubleClick = (event) => {
- const { record, index, onRowDoubleClick } = this.props
- if (onRowDoubleClick) {
- onRowDoubleClick(record, index, event)
- }
- }
+ onContextMenu (event) {
+ const { record, index } = this
+ this.__emit('rowContextmenu', record, index, event)
+ },
- onContextMenu = (event) => {
- const { record, index, onRowContextMenu } = this.props
- if (onRowContextMenu) {
- onRowContextMenu(record, index, event)
- }
- }
+ onMouseEnter (event) {
+ const { record, index, rowKey } = this
+ this.__emit('hover', true, rowKey)
+ this.__emit('rowMouseenter', record, index, event)
+ },
- onMouseEnter = (event) => {
- const { record, index, onRowMouseEnter, onHover, rowKey } = this.props
- onHover(true, rowKey)
- if (onRowMouseEnter) {
- onRowMouseEnter(record, index, event)
- }
- }
+ onMouseLeave (event) {
+ const { record, index, rowKey } = this
+ this.__emit('hover', false, rowKey)
+ this.__emit('rowMouseleave', record, index, event)
+ },
- onMouseLeave = (event) => {
- const { record, index, onRowMouseLeave, onHover, rowKey } = this.props
- onHover(false, rowKey)
- if (onRowMouseLeave) {
- onRowMouseLeave(record, index, event)
- }
- }
+ setExpanedRowHeight () {
+ const { store, rowKey } = this
+ let { expandedRowsHeight } = store.getState()
+ const height = this.rowRef.getBoundingClientRect().height
+ expandedRowsHeight = {
+ ...expandedRowsHeight,
+ [rowKey]: height,
+ }
+ store.setState({ expandedRowsHeight })
+ },
- setExpanedRowHeight () {
- const { store, rowKey } = this.props
- let { expandedRowsHeight } = store.getState()
- const height = this.rowRef.getBoundingClientRect().height
- expandedRowsHeight = {
- ...expandedRowsHeight,
- [rowKey]: height,
- }
- store.setState({ expandedRowsHeight })
- }
+ setRowHeight () {
+ const { store, index } = this
+ const fixedColumnsBodyRowsHeight = store.getState().fixedColumnsBodyRowsHeight.slice()
+ const height = this.rowRef.getBoundingClientRect().height
+ fixedColumnsBodyRowsHeight[index] = height
+ store.setState({ fixedColumnsBodyRowsHeight })
+ },
- setRowHeight () {
- const { store, index } = this.props
- const fixedColumnsBodyRowsHeight = store.getState().fixedColumnsBodyRowsHeight.slice()
- const height = this.rowRef.getBoundingClientRect().height
- fixedColumnsBodyRowsHeight[index] = height
- store.setState({ fixedColumnsBodyRowsHeight })
- }
+ getStyle () {
+ const { height, visible } = this
- getStyle () {
- const { height, visible } = this.props
+ if (height && height !== this.style.height) {
+ this.style = { ...this.style, height }
+ }
- if (height && height !== this.style.height) {
- this.style = { ...this.style, height }
- }
+ if (!visible && !this.style.display) {
+ this.style = { ...this.style, display: 'none' }
+ }
- if (!visible && !this.style.display) {
- this.style = { ...this.style, display: 'none' }
- }
+ return this.style
+ },
- return this.style
- }
+ saveRowRef () {
+ this.rowRef = this.$el
- saveRowRef () {
- this.rowRef = ReactDOM.findDOMNode(this)
+ const { isAnyColumnsFixed, fixed, expandedRow, ancestorKeys } = this
- const { isAnyColumnsFixed, fixed, expandedRow, ancestorKeys } = this.props
+ if (!isAnyColumnsFixed) {
+ return
+ }
- if (!isAnyColumnsFixed) {
- return
- }
+ if (!fixed && expandedRow) {
+ this.setExpanedRowHeight()
+ }
- if (!fixed && expandedRow) {
- this.setExpanedRowHeight()
- }
-
- if (!fixed && ancestorKeys.length >= 0) {
- this.setRowHeight()
- }
- }
+ if (!fixed && ancestorKeys.length >= 0) {
+ this.setRowHeight()
+ }
+ },
+ },
render () {
if (!this.shouldRender) {
@@ -181,7 +181,7 @@ class TableRow extends React.Component {
columns,
record,
index,
- onRow,
+ // onRow,
indent,
indentSize,
hovered,
@@ -191,12 +191,13 @@ class TableRow extends React.Component {
hasExpandIcon,
renderExpandIcon,
renderExpandIconCell,
- } = this.props
-
+ $listeners,
+ } = this
+ const { row: onRow } = $listeners
const BodyRow = components.body.row
const BodyCell = components.body.cell
- let { className } = this.props
+ let className = ''
if (hovered) {
className += ` ${prefixCls}-hover`
@@ -241,22 +242,22 @@ class TableRow extends React.Component {
}
style = { ...style, ...customStyle }
-
+ console.log('rowProps', rowProps)
return (
{cells}
)
- }
+ },
}
function getRowHeight (state, props) {
diff --git a/examples/routes.js b/examples/routes.js
index 41b6a33fc..9ea148250 100644
--- a/examples/routes.js
+++ b/examples/routes.js
@@ -3,7 +3,7 @@ const AsyncComp = () => {
const hashs = window.location.hash.split('/')
const d = hashs[hashs.length - 1]
return {
- component: import(`../components/vc-tree/demo/${d}`),
+ component: import(`../components/vc-table/demo/${d}`),
}
}
export default [
diff --git a/package-lock.json b/package-lock.json
index be35897c4..b2cdd9e77 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "vue-antd-ui",
- "version": "0.1.0",
+ "version": "0.1.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -206,7 +206,7 @@
},
"abab": {
"version": "1.0.4",
- "resolved": "https://registry.npmjs.org/abab/-/abab-1.0.4.tgz",
+ "resolved": "http://registry.npm.taobao.org/abab/download/abab-1.0.4.tgz",
"integrity": "sha1-X6rZwsB/YN12dw9xzwJbYqY8/U4=",
"dev": true,
"optional": true
@@ -251,7 +251,7 @@
},
"acorn-globals": {
"version": "1.0.9",
- "resolved": "https://registry.npmjs.org/acorn-globals/-/acorn-globals-1.0.9.tgz",
+ "resolved": "http://registry.npm.taobao.org/acorn-globals/download/acorn-globals-1.0.9.tgz",
"integrity": "sha1-VbtemGkVB7dFedBRNBMhfDgMVM8=",
"dev": true,
"optional": true,
@@ -261,7 +261,7 @@
"dependencies": {
"acorn": {
"version": "2.7.0",
- "resolved": "https://registry.npmjs.org/acorn/-/acorn-2.7.0.tgz",
+ "resolved": "http://registry.npm.taobao.org/acorn/download/acorn-2.7.0.tgz",
"integrity": "sha1-q259nYhqrKiwhbwzEreaGYQz8Oc=",
"dev": true,
"optional": true
@@ -2491,7 +2491,7 @@
},
"component-classes": {
"version": "1.2.6",
- "resolved": "http://registry.npm.taobao.org/component-classes/download/component-classes-1.2.6.tgz",
+ "resolved": "https://registry.npmjs.org/component-classes/-/component-classes-1.2.6.tgz",
"integrity": "sha1-xkI5TDYYpNiwuJGe/Mu9kw5c1pE=",
"requires": {
"component-indexof": "0.0.3"
@@ -3086,13 +3086,13 @@
},
"cssom": {
"version": "0.3.2",
- "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.2.tgz",
+ "resolved": "http://registry.npm.taobao.org/cssom/download/cssom-0.3.2.tgz",
"integrity": "sha1-uANhcMefB6kP8vFuIihAJ6JDhIs=",
"dev": true
},
"cssstyle": {
"version": "0.2.37",
- "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-0.2.37.tgz",
+ "resolved": "http://registry.npm.taobao.org/cssstyle/download/cssstyle-0.2.37.tgz",
"integrity": "sha1-VBCXI0yyUTyDzu06zdwn/yeYfVQ=",
"dev": true,
"optional": true,
@@ -8076,7 +8076,7 @@
},
"jsdom": {
"version": "7.2.2",
- "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-7.2.2.tgz",
+ "resolved": "http://registry.npm.taobao.org/jsdom/download/jsdom-7.2.2.tgz",
"integrity": "sha1-QLQCdwwr2iNGkJa+6Rq2deOx/G4=",
"dev": true,
"optional": true,
@@ -8100,14 +8100,14 @@
"dependencies": {
"acorn": {
"version": "2.7.0",
- "resolved": "https://registry.npmjs.org/acorn/-/acorn-2.7.0.tgz",
+ "resolved": "http://registry.npm.taobao.org/acorn/download/acorn-2.7.0.tgz",
"integrity": "sha1-q259nYhqrKiwhbwzEreaGYQz8Oc=",
"dev": true,
"optional": true
},
"parse5": {
"version": "1.5.1",
- "resolved": "https://registry.npmjs.org/parse5/-/parse5-1.5.1.tgz",
+ "resolved": "http://registry.npm.taobao.org/parse5/download/parse5-1.5.1.tgz",
"integrity": "sha1-m387DeMr543CQBsXVzzK8Pb1nZQ=",
"dev": true,
"optional": true
@@ -8897,11 +8897,6 @@
"integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=",
"dev": true
},
- "lodash.clonedeep": {
- "version": "4.5.0",
- "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
- "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
- },
"lodash.create": {
"version": "3.1.1",
"resolved": "https://registry.npm.taobao.org/lodash.create/download/lodash.create-3.1.1.tgz",
@@ -8913,11 +8908,6 @@
"lodash._isiterateecall": "3.0.9"
}
},
- "lodash.debounce": {
- "version": "4.0.8",
- "resolved": "https://registry.npm.taobao.org/lodash.debounce/download/lodash.debounce-4.0.8.tgz",
- "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168="
- },
"lodash.escape": {
"version": "3.2.0",
"resolved": "http://registry.npm.taobao.org/lodash.escape/download/lodash.escape-3.2.0.tgz",
@@ -8945,11 +8935,6 @@
"integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=",
"dev": true
},
- "lodash.isequal": {
- "version": "4.5.0",
- "resolved": "https://registry.npm.taobao.org/lodash.isequal/download/lodash.isequal-4.5.0.tgz",
- "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
- },
"lodash.isplainobject": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
@@ -15976,7 +15961,7 @@
},
"symbol-tree": {
"version": "3.2.2",
- "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.2.tgz",
+ "resolved": "http://registry.npm.taobao.org/symbol-tree/download/symbol-tree-3.2.2.tgz",
"integrity": "sha1-rifbOPZgp64uHDt9G8KQgZuFGeY=",
"dev": true,
"optional": true
@@ -16267,7 +16252,7 @@
},
"tr46": {
"version": "0.0.3",
- "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
+ "resolved": "http://registry.npm.taobao.org/tr46/download/tr46-0.0.3.tgz",
"integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=",
"dev": true,
"optional": true
@@ -17031,7 +17016,7 @@
"dependencies": {
"cheerio": {
"version": "0.20.0",
- "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-0.20.0.tgz",
+ "resolved": "http://registry.npm.taobao.org/cheerio/download/cheerio-0.20.0.tgz",
"integrity": "sha1-XHEPK6uVZTJyhCugHG6mGzVF7DU=",
"dev": true,
"requires": {
@@ -17045,7 +17030,7 @@
},
"domhandler": {
"version": "2.3.0",
- "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz",
+ "resolved": "http://registry.npm.taobao.org/domhandler/download/domhandler-2.3.0.tgz",
"integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=",
"dev": true,
"requires": {
@@ -17054,7 +17039,7 @@
},
"domutils": {
"version": "1.5.1",
- "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz",
+ "resolved": "http://registry.npm.taobao.org/domutils/download/domutils-1.5.1.tgz",
"integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=",
"dev": true,
"requires": {
@@ -17064,7 +17049,7 @@
},
"htmlparser2": {
"version": "3.8.3",
- "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz",
+ "resolved": "http://registry.npm.taobao.org/htmlparser2/download/htmlparser2-3.8.3.tgz",
"integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=",
"dev": true,
"requires": {
@@ -17077,7 +17062,7 @@
"dependencies": {
"entities": {
"version": "1.0.0",
- "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz",
+ "resolved": "http://registry.npm.taobao.org/entities/download/entities-1.0.0.tgz",
"integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=",
"dev": true
}
@@ -17085,13 +17070,13 @@
},
"isarray": {
"version": "0.0.1",
- "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
+ "resolved": "http://registry.npm.taobao.org/isarray/download/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=",
"dev": true
},
"loader-utils": {
"version": "0.2.17",
- "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-0.2.17.tgz",
+ "resolved": "http://registry.npm.taobao.org/loader-utils/download/loader-utils-0.2.17.tgz",
"integrity": "sha1-+G5jdNQyBabmxg6RlvF8Apm/s0g=",
"dev": true,
"requires": {
@@ -17103,7 +17088,7 @@
},
"readable-stream": {
"version": "1.1.14",
- "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
+ "resolved": "http://registry.npm.taobao.org/readable-stream/download/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"dev": true,
"requires": {
@@ -17115,7 +17100,7 @@
},
"string_decoder": {
"version": "0.10.31",
- "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
+ "resolved": "http://registry.npm.taobao.org/string_decoder/download/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
}
@@ -17319,7 +17304,7 @@
},
"webidl-conversions": {
"version": "2.0.1",
- "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-2.0.1.tgz",
+ "resolved": "http://registry.npm.taobao.org/webidl-conversions/download/webidl-conversions-2.0.1.tgz",
"integrity": "sha1-O/glj30xjHRDw28uFpQCoaZwNQY=",
"dev": true,
"optional": true
@@ -18038,7 +18023,7 @@
},
"whatwg-url-compat": {
"version": "0.6.5",
- "resolved": "https://registry.npmjs.org/whatwg-url-compat/-/whatwg-url-compat-0.6.5.tgz",
+ "resolved": "http://registry.npm.taobao.org/whatwg-url-compat/download/whatwg-url-compat-0.6.5.tgz",
"integrity": "sha1-AImBEa9om7CXVBzVpFymyHmERb8=",
"dev": true,
"optional": true,
@@ -18168,7 +18153,7 @@
},
"xml-name-validator": {
"version": "2.0.1",
- "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-2.0.1.tgz",
+ "resolved": "http://registry.npm.taobao.org/xml-name-validator/download/xml-name-validator-2.0.1.tgz",
"integrity": "sha1-TYuPHszTQZqjYgYb7O9RXh5VljU=",
"dev": true,
"optional": true
@@ -18250,4 +18235,4 @@
"dev": true
}
}
-}
\ No newline at end of file
+}
From 0c2ff441a72f18476a03582e6beb9017b5f028b9 Mon Sep 17 00:00:00 2001
From: tjz <415800467@qq.com>
Date: Sun, 25 Mar 2018 22:23:04 +0800
Subject: [PATCH 7/8] fix vc-table
---
components/_util/props-util.js | 10 +++--
components/vc-table/demo/className.js | 45 +++++++++++++++++++++
components/vc-table/src/ExpandableRow.jsx | 1 +
components/vc-table/src/ExpandableTable.jsx | 4 +-
components/vc-table/src/TableCell.jsx | 30 ++++++++------
components/vc-table/src/TableHeaderRow.jsx | 17 +++++---
components/vc-table/src/TableRow.jsx | 32 +++++++++------
7 files changed, 103 insertions(+), 36 deletions(-)
create mode 100644 components/vc-table/demo/className.js
diff --git a/components/_util/props-util.js b/components/_util/props-util.js
index d483cbd80..8aec27a94 100644
--- a/components/_util/props-util.js
+++ b/components/_util/props-util.js
@@ -166,10 +166,6 @@ export function getComponentName (opts) {
return opts && (opts.Ctor.options.name || opts.tag)
}
-export function isValidElement (ele) {
- return !!ele.tag
-}
-
export function isEmptyElement (ele) {
return !(ele.tag || ele.text.trim() !== '')
}
@@ -206,6 +202,11 @@ export function mergeProps () {
return props
}
+function isValidElement (element) {
+ const name = element.constructor.name
+ return element.tag && (name === 'VNode' || name === 'VueComponent')
+}
+
export {
hasProp,
filterProps,
@@ -219,5 +220,6 @@ export {
getValueByProp,
parseStyleText,
initDefaultProps,
+ isValidElement,
}
export default hasProp
diff --git a/components/vc-table/demo/className.js b/components/vc-table/demo/className.js
new file mode 100644
index 000000000..9413ea545
--- /dev/null
+++ b/components/vc-table/demo/className.js
@@ -0,0 +1,45 @@
+/* eslint-disable no-console,func-names,react/no-multi-comp */
+import Table from '../index'
+import '../assets/index.less'
+
+const data = [
+ { a: '123', key: '1' },
+ { a: 'cdd', b: 'edd', key: '2' },
+ { a: '1333', c: 'eee', d: 2, key: '3' },
+]
+export default {
+ render () {
+ const columns = [
+ { title: 'title1', dataIndex: 'a',
+ className: 'a',
+ key: 'a', width: 100 },
+ { id: '123', title: 'title2', dataIndex: 'b',
+ className: 'b',
+ key: 'b', width: 100 },
+ { title: 'title3', dataIndex: 'c',
+ className: 'c',
+ key: 'c', width: 200 },
+ {
+ title: 'Operations', dataIndex: '',
+ className: 'd',
+ key: 'd', render (h) {
+ return Operations
+ },
+ },
+ ]
+ return (
+
+
rowClassName and className
+
`row-${i}`}
+ expandedRowRender={record => extra: {record.a}
}
+ expandedRowClassName={(record, i) => `ex-row-${i}`}
+ data={data}
+ class='table'
+ />
+
+ )
+ },
+}
+
diff --git a/components/vc-table/src/ExpandableRow.jsx b/components/vc-table/src/ExpandableRow.jsx
index 77d40a0b9..cfd431197 100644
--- a/components/vc-table/src/ExpandableRow.jsx
+++ b/components/vc-table/src/ExpandableRow.jsx
@@ -112,6 +112,7 @@ const ExpandableRow = {
renderExpandIcon: this.renderExpandIcon,
renderExpandIconCell: this.renderExpandIconCell,
},
+
on: {
rowClick: this.handleRowClick,
},
diff --git a/components/vc-table/src/ExpandableTable.jsx b/components/vc-table/src/ExpandableTable.jsx
index 8308699a8..fc8402b3c 100644
--- a/components/vc-table/src/ExpandableTable.jsx
+++ b/components/vc-table/src/ExpandableTable.jsx
@@ -154,12 +154,11 @@ const ExpandableTable = {
cell: 'td',
},
}
-
return (
{}}
/>
)
},
diff --git a/components/vc-table/src/TableCell.jsx b/components/vc-table/src/TableCell.jsx
index 526f40ce9..8ae309633 100644
--- a/components/vc-table/src/TableCell.jsx
+++ b/components/vc-table/src/TableCell.jsx
@@ -1,5 +1,6 @@
import PropTypes from '../../_util/vue-types'
import get from 'lodash/get'
+import { isValidElement } from '../../_util/props-util'
export default {
name: 'TableCell',
@@ -16,7 +17,7 @@ export default {
methods: {
isInvalidRenderCellText (text) {
// debugger
- return text &&
+ return text && !isValidElement(text) &&
Object.prototype.toString.call(text) === '[object Object]'
},
@@ -28,7 +29,7 @@ export default {
},
},
- render () {
+ render (h) {
const {
record,
indentSize,
@@ -39,8 +40,8 @@ export default {
column,
component: BodyCell,
} = this
- const { dataIndex, render } = column
-
+ const { dataIndex, render, className = '' } = column
+ const cls = column.class || className
// We should return undefined if no dataIndex is specified, but in order to
// be compatible with object-path's behavior, we return the record object instead.
let text
@@ -51,22 +52,29 @@ export default {
} else {
text = get(record, dataIndex)
}
- let tdProps = {}
+ const tdProps = {
+ props: {},
+ attrs: {},
+ class: cls,
+ on: {
+ click: this.handleClick,
+ },
+ }
let colSpan
let rowSpan
if (render) {
- text = render(text, record, index)
+ text = render(h, text, record, index)
if (this.isInvalidRenderCellText(text)) {
- tdProps = text.props || tdProps
- colSpan = tdProps.colSpan
- rowSpan = tdProps.rowSpan
+ tdProps.attrs = text.attrs || text.props || {}
+ colSpan = tdProps.attrs.colSpan
+ rowSpan = tdProps.attrs.rowSpan
text = text.children
}
}
if (column.onCell) {
- tdProps = { ...tdProps, ...column.onCell(record) }
+ tdProps.attrs = { ...tdProps.attrs, ...column.onCell(record) }
}
// Fix https://github.com/ant-design/ant-design/issues/1202
@@ -88,11 +96,9 @@ export default {
if (column.align) {
tdProps.style = { textAlign: column.align }
}
- console.log('tdProps', tdProps)
return (
{indentText}
diff --git a/components/vc-table/src/TableHeaderRow.jsx b/components/vc-table/src/TableHeaderRow.jsx
index 6e23182a1..e87532b51 100644
--- a/components/vc-table/src/TableHeaderRow.jsx
+++ b/components/vc-table/src/TableHeaderRow.jsx
@@ -1,5 +1,6 @@
import PropTypes from '../../_util/vue-types'
import { connect } from '../../_util/store'
+import { mergeProps } from '../../_util/props-util'
const TableHeaderRow = {
props: {
@@ -25,17 +26,23 @@ const TableHeaderRow = {
{row.map((cell, i) => {
const { column, children, className, ...cellProps } = cell
+ const cls = cell.class || className
const customProps = column.onHeaderCell ? column.onHeaderCell(column) : {}
if (column.align) {
cellProps.style = { textAlign: column.align }
}
-
+ const headerCellProps = mergeProps({
+ attrs: {
+ ...cellProps,
+ },
+ class: cls,
+ }, {
+ ...customProps,
+ key: column.key || column.dataIndex || i,
+ })
return (
{children}
diff --git a/components/vc-table/src/TableRow.jsx b/components/vc-table/src/TableRow.jsx
index 1ea693648..a64570267 100644
--- a/components/vc-table/src/TableRow.jsx
+++ b/components/vc-table/src/TableRow.jsx
@@ -2,9 +2,9 @@ import PropTypes from '../../_util/vue-types'
import { connect } from '../../_util/store'
import TableCell from './TableCell'
import { warningOnce } from './utils'
-import { initDefaultProps } from '../../_util/props-util'
+import { initDefaultProps, mergeProps } from '../../_util/props-util'
import BaseMixin from '../../_util/BaseMixin'
-
+function noop () {}
const TableRow = {
name: 'TableRow',
mixins: [BaseMixin],
@@ -71,7 +71,11 @@ const TableRow = {
}
},
watch: {
-
+ visible (val) {
+ if (val) {
+ this.shouldRender = true
+ }
+ },
},
componentWillReceiveProps (nextProps) {
@@ -193,7 +197,7 @@ const TableRow = {
renderExpandIconCell,
$listeners,
} = this
- const { row: onRow } = $listeners
+ const { row: onRow = noop } = $listeners
const BodyRow = components.body.row
const BodyCell = components.body.cell
@@ -242,17 +246,19 @@ const TableRow = {
}
style = { ...style, ...customStyle }
- console.log('rowProps', rowProps)
+ const bodyRowProps = mergeProps({
+ on: {
+ click: this.onRowClick,
+ dblclick: this.onRowDoubleClick,
+ mouseenter: this.onMouseEnter,
+ mouseleave: this.onMouseLeave,
+ contextmenu: this.onContextMenu,
+ },
+ class: rowClassName,
+ }, { ...rowProps, style })
return (
{cells}
From 0cdf29011d2548f886eac9eaba6d321b1cb7a783 Mon Sep 17 00:00:00 2001
From: tjz <415800467@qq.com>
Date: Sun, 25 Mar 2018 22:24:57 +0800
Subject: [PATCH 8/8] update tooltip demo
---
components/tooltip/demo/placement.md | 48 ++++++++++++++--------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/components/tooltip/demo/placement.md b/components/tooltip/demo/placement.md
index 52e346684..dd248b3a6 100644
--- a/components/tooltip/demo/placement.md
+++ b/components/tooltip/demo/placement.md
@@ -12,84 +12,84 @@ The ToolTip has 12 placements choice.