forked from Prowindy/react-data-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
37 lines (32 loc) · 1.02 KB
/
main.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
require('../../css/table-twbs.css');
var React = require('react');
var { DataTable } = require('react-data-components');
var d3 = require('d3');
function buildTable(data) {
var renderMapUrl =
(val, row) =>
<a href={`https://www.google.com/maps?q=${row['LAT']},${row['LON']}`}>
Google Maps
</a>;
var tableColumns = [
{ 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' }
];
return (
<DataTable
className="container"
keys={[ 'NAME', 'OUTLET TYPE', 'STREET ADDRESS' ]}
columns={tableColumns}
initialData={data}
initialPageLength={5}
initialSortBy={{ prop: 'CITY', order: 'descending' }}
pageLengthOptions={[ 5, 20, 50 ]}
/>
);
}
d3.csv('/sample_data.csv', function(error, rows) {
React.render(buildTable(rows), document.body);
});