Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 17 additions & 11 deletions src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? (
<TableHeader
Expand All @@ -215,8 +212,6 @@ const Table = React.createClass({
},

getHeaderRows(columns, currentRow = 0, rows) {
const { prefixCls } = this.props;

rows = rows || [];
rows[currentRow] = rows[currentRow] || [];

Expand All @@ -239,13 +234,12 @@ const Table = React.createClass({
}
if ('rowSpan' in column) {
cell.rowSpan = column.rowSpan;
cell.className += ` ${prefixCls}-rowspan-${cell.rowSpan}`;
}
if (cell.colSpan !== 0) {
rows[currentRow].push(cell);
}
});
return rows;
return rows.filter(row => row.length > 0);
},

getExpandedRow(key, content, visible, className, fixed) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions tests/groupingColumnTitle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});