Skip to content

Commit aeaf513

Browse files
committed
fix(Table): rowHeight changed when resizing, influence virtual
1 parent 36df9c0 commit aeaf513

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

src/table/virtual.jsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ export default function virtual(BaseComponent) {
100100
});
101101
}
102102

103+
if (this.state.rowHeight && 'rowHeight' in nextProps) {
104+
const row = this.getRowNode();
105+
const rowClientHeight = row && row.clientHeight;
106+
if (rowClientHeight !== this.state.rowHeight) {
107+
this.setState({
108+
rowHeight: rowClientHeight
109+
});
110+
}
111+
}
112+
103113
}
104114

105115
componentDidUpdate() {
@@ -140,19 +150,21 @@ export default function virtual(BaseComponent) {
140150

141151
getVisibleRange(ExpectStart) {
142152
const { height, rowHeight } = this.state;
153+
const len = this.props.dataSource.length;
154+
143155
let end, visibleCount = 0;
144156
let start = 0;
145157
if (typeof rowHeight === 'function') {
146158
// try get cell height;
147-
end = 2;
159+
end = 1;
148160
} else {
149161
visibleCount = parseInt(height / rowHeight, 10);
150162

151163
if ('number' === typeof ExpectStart) {
152-
start = ExpectStart;
164+
start = ExpectStart < len ? ExpectStart : 0;
153165
}
154166

155-
end = +start + 1 + visibleCount + 10;
167+
end = Math.min(+start + 1 + visibleCount + 10, len);
156168
}
157169
this.end = end;
158170
this.visibleCount = visibleCount;
@@ -172,11 +184,16 @@ export default function virtual(BaseComponent) {
172184
if (this.hasVirtualData) {
173185
const body = this.bodyNode;
174186
const virtualScrollNode = body.querySelector('div');
175-
const table = virtualScrollNode.querySelector('table');
176187
const { clientHeight, clientWidth } = body;
177-
const { clientWidth: tableClientWidth } = table;
178-
if (clientWidth < tableClientWidth) {
179-
dom.setStyle(virtualScrollNode, 'width', tableClientWidth);
188+
189+
const tableInc = this.tableInc;
190+
const tableNode = findDOMNode(tableInc);
191+
const { prefix } = this.props;
192+
const headerNode = tableNode.querySelector(`.${prefix}table-header table`);
193+
const headerClientWidth = headerNode && headerNode.clientWidth;
194+
195+
if (clientWidth < headerClientWidth) {
196+
dom.setStyle(virtualScrollNode, 'min-width', headerClientWidth);
180197
const leftNode = this.bodyLeftNode;
181198
const rightNode = this.bodyRightNode;
182199
leftNode && dom.setStyle(leftNode, 'max-height', clientHeight);
@@ -223,7 +240,7 @@ export default function virtual(BaseComponent) {
223240
}
224241

225242
getRowNode() {
226-
return findDOMNode(this.tableInc.getRowRef(1));
243+
return findDOMNode(this.tableInc.getRowRef(0));
227244
}
228245

229246
render() {

0 commit comments

Comments
 (0)