From d00aa75116dbeff2b7ea911b1c4004f5a5494b80 Mon Sep 17 00:00:00 2001 From: Alex Kvak Date: Wed, 30 Dec 2015 17:55:46 +0300 Subject: [PATCH 1/2] Ability to remove expand icon column header and merge it with second column header --- README.md | 6 ++++++ src/Table.jsx | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) 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..c33d61fff 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}; } }); }, From aa7c412910c5f84d281be8cade3e0c185c0b65ef Mon Sep 17 00:00:00 2001 From: Alex Kvak Date: Wed, 30 Dec 2015 17:55:46 +0300 Subject: [PATCH 2/2] Ability to remove expand icon column header and merge it with second column header --- README.md | 6 ++++++ src/Table.jsx | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) 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}; } }); },