forked from bvaughn/react-virtualized
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCellMeasurer.DynamicWidthMultiGrid.example.js
80 lines (70 loc) · 2.04 KB
/
CellMeasurer.DynamicWidthMultiGrid.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
import Immutable from 'immutable';
import PropTypes from 'prop-types';
import * as React from 'react';
import CellMeasurer from './CellMeasurer';
import CellMeasurerCache from './CellMeasurerCache';
import MultiGrid from '../MultiGrid';
import styles from './CellMeasurer.example.css';
export default class DynamicWidthMultiGrid 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({
defaultHeight: 30,
defaultWidth: 150,
fixedHeight: true,
});
this._cellRenderer = this._cellRenderer.bind(this);
}
render() {
const {width} = this.props;
return (
<MultiGrid
className={styles.BodyGrid}
columnCount={50}
columnWidth={this._cache.columnWidth}
deferredMeasurementCache={this._cache}
fixedColumnCount={1}
fixedRowCount={0}
height={400}
overscanColumnCount={0}
overscanRowCount={0}
cellRenderer={this._cellRenderer}
rowCount={50}
rowHeight={30}
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});
let content = getContent({index: rowIndex, datum, long: false});
if (columnIndex === 0) {
content = content.substr(0, 50);
}
return (
<CellMeasurer
cache={this._cache}
columnIndex={columnIndex}
key={key}
parent={parent}
rowIndex={rowIndex}>
<div
className={classNames}
style={{
...style,
whiteSpace: 'nowrap',
}}>
{content}
</div>
</CellMeasurer>
);
}
}