diff --git a/README.md b/README.md index c359d0398..b395482f7 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,12 @@ var table = React.render( false whether render expandIcon as a cell + + expandIconColumnHeader + Boolean + true + whether render expandIcon column header. If not and expandIconAsCell is true, second column header will span first column header. + rowKey Function(recode,index):string diff --git a/src/Table.jsx b/src/Table.jsx index a73a212b7..296941812 100644 --- a/src/Table.jsx +++ b/src/Table.jsx @@ -5,6 +5,7 @@ const Table = React.createClass({ propTypes: { data: React.PropTypes.array, expandIconAsCell: React.PropTypes.bool, + expandIconColumnHeader: React.PropTypes.bool, expandedRowKeys: React.PropTypes.array, defaultExpandedRowKeys: React.PropTypes.array, useFixedHeader: React.PropTypes.bool, @@ -25,6 +26,7 @@ const Table = React.createClass({ data: [], useFixedHeader: false, expandIconAsCell: false, + expandIconColumnHeader: true, columns: [], defaultExpandedRowKeys: [], rowKey(o) { @@ -108,7 +110,7 @@ const Table = React.createClass({ getThs() { let ths = []; - if (this.props.expandIconAsCell) { + if (this.props.expandIconAsCell && this.props.expandIconColumnHeader) { ths.push({ key: 'rc-table-expandIconAsCell', className: `${this.props.prefixCls}-expand-icon-th`, @@ -116,9 +118,15 @@ const Table = React.createClass({ }); } ths = ths.concat(this.props.columns); - return ths.map((c)=> { - if (c.colSpan !== 0) { - return {c.title}; + return ths.map((c, index) => { + let colSpan = c.colSpan; + if (colSpan !== 0) { + if (this.props.expandIconAsCell && !this.props.expandIconColumnHeader && index === 0) { + // if expand icon is rendered as icon and expandIconColumnHeader is false, we need to span second column header + colSpan = colSpan || 1; + colSpan += 1; + } + return {c.title}; } }); },