forked from bvaughn/react-virtualized
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCellMeasurer.DynamicWidthGrid.example.js
74 lines (65 loc) · 1.9 KB
/
CellMeasurer.DynamicWidthGrid.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
import Immutable from 'immutable';
import PropTypes from 'prop-types';
import * as React from 'react';
import CellMeasurer from './CellMeasurer';
import CellMeasurerCache from './CellMeasurerCache';
import Grid from '../Grid';
import styles from './CellMeasurer.example.css';
export default class DynamicWidthGrid extends React.PureComponent {
static propTypes = {
getClassName: PropTypes.func.isRequired,
getContent: PropTypes.func.isRequired,
list: PropTypes.instanceOf(Immutable.List).isRequired,
width: PropTypes.number.isRequired,
};
constructor(props, context) {
super(props, context);
this._cache = new CellMeasurerCache({
defaultWidth: 100,
fixedHeight: true,
});
this._cellRenderer = this._cellRenderer.bind(this);
}
render() {
const {width} = this.props;
return (
<Grid
className={styles.BodyGrid}
columnCount={1000}
columnWidth={this._cache.columnWidth}
deferredMeasurementCache={this._cache}
height={400}
overscanColumnCount={0}
overscanRowCount={2}
cellRenderer={this._cellRenderer}
rowCount={50}
rowHeight={35}
width={width}
/>
);
}
_cellRenderer({columnIndex, key, parent, rowIndex, style}) {
const {getClassName, getContent, list} = this.props;
const datum = list.get((rowIndex + columnIndex) % list.size);
const classNames = getClassName({columnIndex, rowIndex});
const content = getContent({index: columnIndex, datum, long: false});
return (
<CellMeasurer
cache={this._cache}
columnIndex={columnIndex}
key={key}
parent={parent}
rowIndex={rowIndex}>
<div
className={classNames}
style={{
...style,
height: 35,
whiteSpace: 'nowrap',
}}>
{content}
</div>
</CellMeasurer>
);
}
}