forked from bvaughn/react-virtualized
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCellMeasurer.DynamicHeightTableColumn.example.js
92 lines (81 loc) · 2.2 KB
/
CellMeasurer.DynamicHeightTableColumn.example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import Immutable from 'immutable';
import PropTypes from 'prop-types';
import * as React from 'react';
import CellMeasurer from './CellMeasurer';
import CellMeasurerCache from './CellMeasurerCache';
import {Column, Table} from '../Table';
import styles from './CellMeasurer.example.css';
export default class DynamicHeightTableColumn extends React.PureComponent {
static propTypes = {
list: PropTypes.instanceOf(Immutable.List).isRequired,
width: PropTypes.number.isRequired,
};
_cache = new CellMeasurerCache({
fixedWidth: true,
minHeight: 25,
});
_lastRenderedWidth = this.props.width;
render() {
const {width} = this.props;
if (this._lastRenderedWidth !== this.props.width) {
this._lastRenderedWidth = this.props.width;
this._cache.clearAll();
}
return (
<Table
deferredMeasurementCache={this._cache}
headerHeight={20}
height={400}
overscanRowCount={2}
rowClassName={styles.tableRow}
rowHeight={this._cache.rowHeight}
rowGetter={this._rowGetter}
rowCount={1000}
width={width}>
<Column
className={styles.tableColumn}
dataKey="name"
label="Name"
width={125}
/>
<Column
className={styles.tableColumn}
dataKey="color"
label="Color"
width={75}
/>
<Column
width={width - 200}
dataKey="random"
label="Dynamic text"
cellRenderer={this._columnCellRenderer}
/>
</Table>
);
}
_columnCellRenderer = ({dataKey, parent, rowIndex}) => {
const {list} = this.props;
const datum = list.get(rowIndex % list.size);
const content = rowIndex % 5 === 0 ? '' : datum.randomLong;
return (
<CellMeasurer
cache={this._cache}
columnIndex={0}
key={dataKey}
parent={parent}
rowIndex={rowIndex}>
<div
className={styles.tableColumn}
style={{
whiteSpace: 'normal',
}}>
{content}
</div>
</CellMeasurer>
);
};
_rowGetter = ({index}) => {
const {list} = this.props;
return list.get(index % list.size);
};
}