forked from bvaughn/react-virtualized
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMultiGrid.example.js
142 lines (128 loc) · 3.76 KB
/
MultiGrid.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/** @flow */
import Immutable from 'immutable';
import PropTypes from 'prop-types';
import * as React from 'react';
import {
ContentBox,
ContentBoxHeader,
ContentBoxParagraph,
} from '../demo/ContentBox';
import {LabeledInput, InputRow} from '../demo/LabeledInput';
import AutoSizer from '../AutoSizer';
import MultiGrid from './MultiGrid';
import styles from './MultiGrid.example.css';
const STYLE = {
border: '1px solid #ddd',
};
const STYLE_BOTTOM_LEFT_GRID = {
borderRight: '2px solid #aaa',
backgroundColor: '#f7f7f7',
};
const STYLE_TOP_LEFT_GRID = {
borderBottom: '2px solid #aaa',
borderRight: '2px solid #aaa',
fontWeight: 'bold',
};
const STYLE_TOP_RIGHT_GRID = {
borderBottom: '2px solid #aaa',
fontWeight: 'bold',
};
export default class MultiGridExample extends React.PureComponent {
static contextTypes = {
list: PropTypes.instanceOf(Immutable.List).isRequired,
};
constructor(props, context) {
super(props, context);
this.state = {
fixedColumnCount: 2,
fixedRowCount: 1,
scrollToColumn: 0,
scrollToRow: 0,
};
this._cellRenderer = this._cellRenderer.bind(this);
this._onFixedColumnCountChange = this._createEventHandler(
'fixedColumnCount',
);
this._onFixedRowCountChange = this._createEventHandler('fixedRowCount');
this._onScrollToColumnChange = this._createEventHandler('scrollToColumn');
this._onScrollToRowChange = this._createEventHandler('scrollToRow');
}
render() {
return (
<ContentBox>
<ContentBoxHeader
text="MultiGrid"
sourceLink="https://github.com/bvaughn/react-virtualized/blob/master/source/MultiGrid/MultiGrid.example.js"
docsLink="https://github.com/bvaughn/react-virtualized/blob/master/docs/MultiGrid.md"
/>
<ContentBoxParagraph>
This component stitches together several grids to provide a fixed
column/row interface.
</ContentBoxParagraph>
<InputRow>
{this._createLabeledInput(
'fixedColumnCount',
this._onFixedColumnCountChange,
)}
{this._createLabeledInput(
'fixedRowCount',
this._onFixedRowCountChange,
)}
{this._createLabeledInput(
'scrollToColumn',
this._onScrollToColumnChange,
)}
{this._createLabeledInput('scrollToRow', this._onScrollToRowChange)}
</InputRow>
<AutoSizer disableHeight>
{({width}) => (
<MultiGrid
{...this.state}
cellRenderer={this._cellRenderer}
columnWidth={75}
columnCount={50}
enableFixedColumnScroll
enableFixedRowScroll
height={300}
rowHeight={40}
rowCount={100}
style={STYLE}
styleBottomLeftGrid={STYLE_BOTTOM_LEFT_GRID}
styleTopLeftGrid={STYLE_TOP_LEFT_GRID}
styleTopRightGrid={STYLE_TOP_RIGHT_GRID}
width={width}
hideTopRightGridScrollbar
hideBottomLeftGridScrollbar
/>
)}
</AutoSizer>
</ContentBox>
);
}
_cellRenderer({columnIndex, key, rowIndex, style}) {
return (
<div className={styles.Cell} key={key} style={style}>
{columnIndex}, {rowIndex}
</div>
);
}
_createEventHandler(property) {
return event => {
const value = parseInt(event.target.value, 10) || 0;
this.setState({
[property]: value,
});
};
}
_createLabeledInput(property, eventHandler) {
const value = this.state[property];
return (
<LabeledInput
label={property}
name={property}
onChange={eventHandler}
value={value}
/>
);
}
}