forked from adazzle/react-data-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid.js
108 lines (101 loc) · 4.14 KB
/
Grid.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
const React = require('react');
const PropTypes = React.PropTypes;
const Header = require('./Header');
const Viewport = require('./Viewport');
const GridScrollMixin = require('./GridScrollMixin');
const DOMMetrics = require('./DOMMetrics');
const cellMetaDataShape = require('./PropTypeShapes/CellMetaDataShape');
const Grid = React.createClass({
propTypes: {
rowGetter: PropTypes.oneOfType([PropTypes.array, PropTypes.func]).isRequired,
columns: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
columnMetrics: PropTypes.object,
minHeight: PropTypes.number,
totalWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
headerRows: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
rowHeight: PropTypes.number,
rowRenderer: PropTypes.func,
emptyRowsView: PropTypes.func,
expandedRows: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
selectedRows: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
rowsCount: PropTypes.number,
onRows: PropTypes.func,
sortColumn: React.PropTypes.string,
sortDirection: React.PropTypes.oneOf(['ASC', 'DESC', 'NONE']),
rowOffsetHeight: PropTypes.number.isRequired,
onViewportKeydown: PropTypes.func.isRequired,
onViewportDragStart: PropTypes.func.isRequired,
onViewportDragEnd: PropTypes.func.isRequired,
onViewportDoubleClick: PropTypes.func.isRequired,
onColumnResize: PropTypes.func,
onSort: PropTypes.func,
cellMetaData: PropTypes.shape(cellMetaDataShape),
rowKey: PropTypes.string.isRequired,
rowScrollTimeout: PropTypes.number
},
mixins: [
GridScrollMixin,
DOMMetrics.MetricsComputatorMixin
],
getDefaultProps() {
return {
rowHeight: 35,
minHeight: 350
};
},
getStyle: function(): { overflow: string; outline: number; position: string; minHeight: number } {
return {
overflow: 'hidden',
outline: 0,
position: 'relative',
minHeight: this.props.minHeight
};
},
render(): ?ReactElement {
let headerRows = this.props.headerRows || [{ref: 'row'}];
let EmptyRowsView = this.props.emptyRowsView;
return (
<div {...this.props} style={this.getStyle()} className="react-grid-Grid">
<Header
ref="header"
columnMetrics={this.props.columnMetrics}
onColumnResize={this.props.onColumnResize}
height={this.props.rowHeight}
totalWidth={this.props.totalWidth}
headerRows={headerRows}
sortColumn={this.props.sortColumn}
sortDirection={this.props.sortDirection}
onSort={this.props.onSort}
/>
{this.props.rowsCount >= 1 || (this.props.rowsCount === 0 && !this.props.emptyRowsView) ?
<div ref="viewPortContainer" onKeyDown={this.props.onViewportKeydown} onDoubleClick={this.props.onViewportDoubleClick} onDragStart={this.props.onViewportDragStart} onDragEnd={this.props.onViewportDragEnd}>
<Viewport
ref="viewport"
rowKey={this.props.rowKey}
width={this.props.columnMetrics.width}
rowHeight={this.props.rowHeight}
rowRenderer={this.props.rowRenderer}
rowGetter={this.props.rowGetter}
rowsCount={this.props.rowsCount}
selectedRows={this.props.selectedRows}
expandedRows={this.props.expandedRows}
columnMetrics={this.props.columnMetrics}
totalWidth={this.props.totalWidth}
onScroll={this.onScroll}
onRows={this.props.onRows}
cellMetaData={this.props.cellMetaData}
rowOffsetHeight={this.props.rowOffsetHeight || this.props.rowHeight * headerRows.length}
minHeight={this.props.minHeight}
rowScrollTimeout={this.props.rowScrollTimeout}
/>
</div>
:
<div ref="emptyView" className="react-grid-Empty">
<EmptyRowsView />
</div>
}
</div>
);
}
});
module.exports = Grid;