forked from dc-js/dc.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
table-pagination.html
79 lines (72 loc) · 2.2 KB
/
table-pagination.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
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="en">
<head>
<title>dc.js - Table of Aggregated Data</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/dc.css"/>
</head>
<body>
<div class="container">
<script type="text/javascript" src="header.js"></script>
<table id="test"></table>
<div id="paging">
Showing <span id="begin"></span>-<span id="end"></span> of <span id="size"></span>.
<input id="last" class="btn" type="Button" value="Last" onclick="javascript:last()" />
<input id="next" class="btn" type="button" value="Next" onclick="javascript:next()"/>
</div>
<script type="text/javascript" src="../js/d3.js"></script>
<script type="text/javascript" src="../js/crossfilter.js"></script>
<script type="text/javascript" src="../js/dc.js"></script>
<script type="text/javascript">
var chart = dc.dataTable("#test");
var ndx;
d3.csv("morley.csv", function(error, experiments) {
ndx = crossfilter(experiments);
var fmt = d3.format('02d');
var runDimension = ndx.dimension(function(d) {return [fmt(+d.Expt),fmt(+d.Run)];}),
grouping = function (d) { return d.Expt;};
chart
.width(768)
.height(480)
.dimension(runDimension)
.group(grouping)
.size(Infinity)
.columns(['Run', 'Speed'])
.sortBy(function (d) { return [fmt(+d.Expt),fmt(+d.Run)]; })
.order(d3.ascending);
update();
chart.render();
});
// use odd page size to show the effect better
var ofs = 0, pag = 17;
function display() {
d3.select('#begin')
.text(ofs);
d3.select('#end')
.text(ofs+pag-1);
d3.select('#last')
.attr('disabled', ofs-pag<0 ? 'true' : null);
d3.select('#next')
.attr('disabled', ofs+pag>=ndx.size() ? 'true' : null);
d3.select('#size').text(ndx.size());
}
function update() {
chart.beginSlice(ofs);
chart.endSlice(ofs+pag);
display();
}
function next() {
ofs += pag;
update();
chart.redraw();
}
function last() {
ofs -= pag;
update();
chart.redraw();
}
</script>
</div>
</body>
</html>