From 229790cf15634dd72cbdc88e7df670ed672d06b5 Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Fri, 9 Sep 2016 16:52:42 +0800 Subject: [PATCH] Improve grouping columns heigh computing. --- assets/index.less | 10 ---------- src/Table.jsx | 28 +++++++++++++++++----------- tests/groupingColumnTitle.spec.js | 4 ++-- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/assets/index.less b/assets/index.less index 33d105c8b..97aa4337f 100644 --- a/assets/index.less +++ b/assets/index.less @@ -6,7 +6,6 @@ @table-head-background-color: #f7f7f7; @vertical-padding: 16px; @horizontal-padding: 8px; -@row-height: @font-size-base * @line-height + @vertical-padding * 2; .@{tablePrefixCls} { font-size: @font-size-base; @@ -175,15 +174,6 @@ width: auto; background: #fff; } - - .generate-rowspan(10); - - .generate-rowspan(@n, @i: 1) when (@i =< @n) { - th.@{tablePrefixCls}-rowspan-@{i} { - height: @row-height * @i - @vertical-padding * 2; - } - .generate-rowspan(@n, (@i + 1)); - } } &-fixed-left { diff --git a/src/Table.jsx b/src/Table.jsx index a579542ae..934a2cfa5 100644 --- a/src/Table.jsx +++ b/src/Table.jsx @@ -194,16 +194,13 @@ const Table = React.createClass({ if (expandIconAsCell && fixed !== 'right') { rows[0].unshift({ key: 'rc-table-expandIconAsCell', - className: `${prefixCls}-expand-icon-th ${prefixCls}-rowspan-${rows.length}`, + className: `${prefixCls}-expand-icon-th`, title: '', rowSpan: rows.length, }); } - const { fixedColumnsHeadRowsHeight } = this.state; - const trStyle = (fixedColumnsHeadRowsHeight[0] && columns) ? { - height: fixedColumnsHeadRowsHeight[0], - } : null; + const trStyle = this.getHeaderRowStyle(columns, rows); return showHeader ? ( row.length > 0); }, getExpandedRow(key, content, visible, className, fixed) { @@ -565,6 +559,18 @@ const Table = React.createClass({ return this.getLeafColumns(columns).length; }, + getHeaderRowStyle(columns, rows) { + const { fixedColumnsHeadRowsHeight } = this.state; + const headerHeight = fixedColumnsHeadRowsHeight[0]; + if (headerHeight && columns) { + if (headerHeight === 'auto') { + return { height: 'auto' }; + } + return { height: headerHeight / rows.length }; + } + return null; + }, + // add appropriate rowspan and colspan to column groupColumns(columns, currentRow = 0, parentColumn = {}, rows = []) { // track how many rows we got @@ -607,8 +613,8 @@ const Table = React.createClass({ syncFixedTableRowHeight() { const { prefixCls } = this.props; const headRows = this.refs.headTable ? - this.refs.headTable.querySelectorAll('tr') : - this.refs.bodyTable.querySelectorAll('thead > tr'); + this.refs.headTable.querySelectorAll('thead') : + this.refs.bodyTable.querySelectorAll('thead'); const bodyRows = this.refs.bodyTable.querySelectorAll(`.${prefixCls}-row`) || []; const fixedColumnsHeadRowsHeight = [].map.call( headRows, row => row.getBoundingClientRect().height || 'auto' diff --git a/tests/groupingColumnTitle.spec.js b/tests/groupingColumnTitle.spec.js index 680bf859e..09743b81e 100644 --- a/tests/groupingColumnTitle.spec.js +++ b/tests/groupingColumnTitle.spec.js @@ -114,12 +114,12 @@ describe('Table with grouping columns', () => { div ); + const fixedRows = node.find('.rc-table-fixed-left thead tr'); const titleA = node.find('.rc-table-fixed-left .title-a'); const titleE = node.find('.rc-table-fixed-right .title-e'); + expect(fixedRows.length).to.be(1); expect(titleA.attr('rowspan')).to.be('2'); - expect(titleA.hasClass('rc-table-rowspan-2')).to.be(true); expect(titleE.attr('rowspan')).to.be('2'); - expect(titleE.hasClass('rc-table-rowspan-2')).to.be(true); }); });