-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo2.html
67 lines (63 loc) · 2.56 KB
/
demo2.html
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
<!doctype html>
<html>
<head>
<title>RTable demo</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap-theme.min.css">
</head>
<body>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react-with-addons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react-dom.min.js"></script>
<script src="dist/rtable.js"></script>
<div class="container">
<h1><a href="https://github.com/Kos/rtable">RTable</a> demo</h1>
<p>Uses StackOverflow API as the example data source.</p>
<div id="react-container"</div>
</div>
<script>
var StackOverflowUsers = new RTable.AjaxDataSource({
baseUrl: "https://api.stackexchange.com/2.2/users?site=stackoverflow",
onResponse: function(response, dataRequest) {
var data = response.json;
return {
count: null,
next: data.has_more ? dataRequest.page + 1 : null,
previous: dataRequest.page > 1 ? dataRequest.page - 1 : null,
results: data.items || []
};
}
});
function pre(str) {
return React.createElement('pre', { style: { 'whiteSpace': 'pre-wrap' }}, str);
}
function img(src, width) {
return React.createElement("img", { src: src, width: width });
}
function date(timestamp) {
var dateString = new Date(timestamp*1000).toDateString();
return React.createElement("span", { className: "date"}, [dateString]);
}
ReactDOM.render(
React.createElement(RTable, {
dataSource: StackOverflowUsers,
columns: [
{name: "author_avatar", label: "", get: function(user) { return user.profile_image ? img(user.profile_image) : ''; }},
{name: "display_name", label: "Name"},
{name: "reputation", label: "Reputation"},
{name: "last_access_date", label: "Last access", get: function(user) { return date(user.last_access_date); }},
{name: "website_url", label: "Website"},
],
filters: [
{'label': 'Page size', 'name': 'pagesize', 'choices': [
// TODO respect the first choice if it's non null
null, 10, 30, 50
]}
],
// TODO showcase ordering on reputation and display_name
}),
document.getElementById('react-container')
);
</script>
</body>
</html>