forked from carlosrocha/react-data-components
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFluxTable.js
More file actions
89 lines (76 loc) · 2.32 KB
/
FluxTable.js
File metadata and controls
89 lines (76 loc) · 2.32 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
87
88
89
var React = require('react');
var { Table, Pagination, SelectField, SearchField } =
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>;
function getStateFromStore() {
return { data: DataStore.getData() };
}
var FluxTable = React.createClass({
keys: [ 'NAME', 'OUTLET TYPE', 'STREET ADDRESS' ],
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' }
],
getInitialState() {
return getStateFromStore();
},
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">
<SelectField
id="page-menu"
label="Page size:"
value={data.pageSize}
options={[ 5, 10, 50 ]}
onChange={ViewActionCreators.changePageSize}
/>
<SearchField
id="search-field"
label="Search:"
value={data.filterValues['globalSearch']}
onChange={ViewActionCreators.filter.bind(this, 'globalSearch')}
/>
</div>
<div className="col-xs-8">
<Pagination
className="pagination pull-right"
currentPage={data.pageNumber}
totalPages={data.totalPages}
onChangePage={ViewActionCreators.changePageNumber}
/>
</div>
</div>
<Table
className="table table-bordered"
columns={this.columns}
keys={this.keys}
dataArray={data.page}
sortBy={data.sortBy}
onSort={ViewActionCreators.sort}
/>
</div>
);
}
});
module.exports = FluxTable;