Skip to content

Commit a56ee2a

Browse files
authored
fix: horizontal scrollbar in flex mode with dynamic row height (#183)
1 parent 3466215 commit a56ee2a

File tree

4 files changed

+55
-20
lines changed

4 files changed

+55
-20
lines changed

src/BaseTable.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ class BaseTable extends React.PureComponent {
100100
this.columnManager.reset(columns, fixed);
101101

102102
if (this.props.estimatedRowHeight && fixed) {
103-
this.resetColumnWidthCache(false);
104-
105103
if (!this.columnManager.hasLeftFrozenColumns()) {
106104
this._leftRowHeightMap = {};
107105
}
@@ -223,15 +221,6 @@ class BaseTable extends React.PureComponent {
223221
this.rightTable && this.rightTable.resetAfterRowIndex(rowIndex, shouldForceUpdate);
224222
}
225223

226-
/**
227-
* Reset cached column width, should be used only in dynamic mode(estimatedRowHeight is provided)
228-
*/
229-
resetColumnWidthCache(shouldForceUpdate = true) {
230-
this.table && this.table.resetAfterColumnIndex(0, shouldForceUpdate);
231-
this.leftTable && this.leftTable.resetAfterColumnIndex(0, shouldForceUpdate);
232-
this.rightTable && this.rightTable.resetAfterColumnIndex(0, shouldForceUpdate);
233-
}
234-
235224
/**
236225
* Reset cached row heights, should be used only in dynamic mode(estimatedRowHeight is provided)
237226
*/
@@ -955,10 +944,6 @@ class BaseTable extends React.PureComponent {
955944
this.columnManager.setColumnWidth(key, width);
956945
this.setState({ resizingWidth: width });
957946

958-
if (this.props.estimatedRowHeight && this.props.fixed) {
959-
this.resetColumnWidthCache();
960-
}
961-
962947
const column = this.columnManager.getColumn(key);
963948
this.props.onColumnResize({ column, width });
964949
}

src/GridTable.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import cn from 'classnames';
44
import { FixedSizeGrid, VariableSizeGrid } from 'react-window';
5+
import memoize from 'memoize-one';
56

67
import Header from './TableHeader';
78

@@ -18,6 +19,10 @@ class GridTable extends React.PureComponent {
1819
this._itemKey = this._itemKey.bind(this);
1920
this._getBodyWidth = this._getBodyWidth.bind(this);
2021
this._handleItemsRendered = this._handleItemsRendered.bind(this);
22+
this._resetColumnWidthCache = memoize(bodyWidth => {
23+
if (!this.props.estimatedRowHeight) return;
24+
this.bodyRef && this.bodyRef.resetAfterColumnIndex(0, false);
25+
});
2126

2227
this.renderRow = this.renderRow.bind(this);
2328
}
@@ -27,11 +32,6 @@ class GridTable extends React.PureComponent {
2732
this.bodyRef && this.bodyRef.resetAfterRowIndex(rowIndex, shouldForceUpdate);
2833
}
2934

30-
resetAfterColumnIndex(columnIndex = 0, shouldForceUpdate) {
31-
if (!this.props.estimatedRowHeight) return;
32-
this.bodyRef && this.bodyRef.resetAfterColumnIndex(columnIndex, shouldForceUpdate);
33-
}
34-
3535
forceUpdateTable() {
3636
this.headerRef && this.headerRef.forceUpdate();
3737
this.bodyRef && this.bodyRef.forceUpdate();
@@ -99,6 +99,8 @@ class GridTable extends React.PureComponent {
9999
const cls = cn(`${classPrefix}__table`, className);
100100
const containerProps = containerStyle ? { style: containerStyle } : null;
101101
const Grid = estimatedRowHeight ? VariableSizeGrid : FixedSizeGrid;
102+
103+
this._resetColumnWidthCache(bodyWidth);
102104
return (
103105
<div role="table" className={cls} {...containerProps}>
104106
<Grid

website/siteConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ module.exports = {
192192
title: 'Expand - Controlled',
193193
path: '/examples/expand-controlled',
194194
},
195+
{
196+
title: 'Detail View',
197+
path: '/examples/detail-view',
198+
},
195199
{
196200
title: 'Use IsScrolling',
197201
path: '/examples/is-scrolling',
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const columns = generateColumns(10)
2+
const data = generateData(columns, 200)
3+
4+
data.forEach(x => {
5+
x.children = [
6+
{
7+
id: `${x.id}-detail`,
8+
content: faker.lorem.paragraphs(),
9+
},
10+
]
11+
})
12+
13+
const GlobalStyle = createGlobalStyle`
14+
.BaseTable__row--depth-0 {
15+
height: 50px;
16+
}
17+
18+
.BaseTable__row--depth-0 .BaseTable__row-cell-text {
19+
overflow: hidden;
20+
text-overflow: ellipsis;
21+
white-space: nowrap;
22+
}
23+
`
24+
25+
const Row = styled.div`
26+
padding: 15px;
27+
`
28+
const rowRenderer = ({ rowData, cells }) => {
29+
if (rowData.content) return <Row>{rowData.content}</Row>
30+
return cells
31+
}
32+
33+
export default () => (
34+
<>
35+
<GlobalStyle />
36+
<Table
37+
expandColumnKey={columns[0].key}
38+
estimatedRowHeight={50}
39+
columns={columns}
40+
data={data}
41+
rowRenderer={rowRenderer}
42+
/>
43+
</>
44+
)

0 commit comments

Comments
 (0)