-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathVirtualizedLazyTable.js
More file actions
86 lines (74 loc) · 2.58 KB
/
VirtualizedLazyTable.js
File metadata and controls
86 lines (74 loc) · 2.58 KB
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
import React, { Component } from 'react'
import {connect} from 'react-redux'
import {moduleName, fetchLazy, selectEvent, eventListSelector} from '../../ducks/events'
import {Table, Column, InfiniteLoader} from 'react-virtualized'
import 'react-virtualized/styles.css'
import EventTableRow from './EventsTableRow'
function rowRenderer (props) {
return <EventTableRow {...props} />
}
export class EventLazyTable extends Component {
static propTypes = {
};
componentDidMount() {
this.props.fetchLazy()
}
render() {
const {loaded, events} = this.props
return (
<InfiniteLoader
isRowLoaded={this.isRowLoaded}
rowCount={loaded ? events.length : events.length + 1}
loadMoreRows={this.loadMoreRows}
>
{({onRowsRendered, registerChild}) =>
<Table
ref={registerChild}
rowCount={events.length}
rowGetter={this.rowGetter}
rowHeight={40}
headerHeight={50}
overscanRowCount={1}
width={700}
height={300}
onRowClick={this.handleRowClick}
onRowsRendered={onRowsRendered}
rowRenderer={rowRenderer}
rowClassName="test__event_table_row"
>
<Column
label="title"
dataKey="title"
width={300}
/>
<Column
label="where"
dataKey="where"
width={250}
/>
<Column
label="when"
dataKey="month"
width={150}
/>
</Table>
}
</InfiniteLoader>
)
}
isRowLoaded = ({ index }) => index < this.props.events.length
loadMoreRows = () => {
this.props.fetchLazy()
}
rowGetter = ({ index }) => {
return this.props.events[index]
}
handleRowClick = ({rowData}) => {
const {selectEvent} = this.props
selectEvent && selectEvent(rowData.uid)
}
}
export default connect(state => ({
events: eventListSelector(state),
loading: state[moduleName].loading
}), {fetchLazy, selectEvent})(EventLazyTable)