forked from carlosrocha/react-data-components
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFluxTable.js
89 lines (76 loc) · 2.34 KB
/
FluxTable.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
var React = require('react');
var RDC = require('react-data-components');
var DataStore = require('./DataStore');
var ViewActionCreators = require('./ViewActionCreators');
var renderMapUrl =
(val, row) =>
<a href={`https://www.google.com/maps?q=${row['LAT']},${row['LON']}`}>
Google Maps
</a>;
var keys = [ 'NAME', 'OUTLET TYPE', 'STREET ADDRESS' ];
var columns = [
{ title: 'Name', prop: 'NAME' },
{ title: 'City', prop: 'CITY' },
{ title: 'Street address', prop: 'STREET ADDRESS' },
{ title: 'Phone', prop: 'PHONE NUMBER', defaultContent: '<no phone>' },
{ title: 'Map', render: renderMapUrl, className: 'text-center' }
];
function getStateFromStore() {
return { data: DataStore.getData() };
}
class FluxTable extends React.Component {
constructor() {
this.state = getStateFromStore();
this.handleStoreChange = this.handleStoreChange.bind(this);
}
componentDidMount() {
DataStore.addChangeListener(this.handleStoreChange);
}
componentWillUnmount() {
DataStore.removeChangeListener(this.handleStoreChange);
}
handleStoreChange() {
this.setState(getStateFromStore());
}
render() {
var {data} = this.state;
return (
<div className="container">
<div className="row">
<div className="col-xs-4">
<RDC.SelectField
id="page-menu"
label="Page size:"
value={data.pageSize}
options={[ 5, 10, 50 ]}
onChange={ViewActionCreators.changePageSize}
/>
<RDC.SearchField
id="search-field"
label="Search:"
value={data.filterValues['globalSearch']}
onChange={ViewActionCreators.filter.bind(this, 'globalSearch')}
/>
</div>
<div className="col-xs-8">
<RDC.Pagination
className="pagination pull-right"
currentPage={data.pageNumber}
totalPages={data.totalPages}
onChangePage={ViewActionCreators.changePageNumber}
/>
</div>
</div>
<RDC.Table
className="table table-bordered"
columns={columns}
keys={keys}
dataArray={data.page}
sortBy={data.sortBy}
onSort={ViewActionCreators.sort}
/>
</div>
);
}
}
module.exports = FluxTable;