-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample.html
More file actions
144 lines (121 loc) · 4.4 KB
/
Copy pathexample.html
File metadata and controls
144 lines (121 loc) · 4.4 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<html>
<head>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery.mousewheel.js"></script>
<script type="text/javascript" src="tilava-table.js"></script>
<title>Tilava Table Example</title>
<style type="text/css">
table, th, td { border: 1px solid black; }
.template { display: none; }
tr.even td { background-color: #eee; }
tr.odd td { background-color: #fff; }
</style>
<script type="text/javascript">
function getRows(howMany) {
var records = [];
for (var i = 0; i < howMany; i++) {
records.push({
time: "2012-01-04 11:07:27",
transactionId: rowNum,
category: (Math.random() > .5) ? "Hardlines" : "Softlines",
price: Math.floor(Math.random() * 1000),
quantity: Math.floor(Math.random() * 25)
});
rowNum++;
}
return records;
}
function setupClickHandlers() {
$("#clear").click(function() {
t.clear();
});
$("#append-100k").click(function() {
t.appendRecords(getRows(100000));
});
$("#append-1").click(function() {
t.appendRecords(getRows(1));
});
$("#prepend-100k").click(function() {
t.prependRecords(getRows(100000));
});
$("#prepend-1").click(function() {
t.prependRecords(getRows(1));
});
$("#insert").click(function() {
t.insertRecord($("#insert-index").val(), getRows(1)[0]);
});
$("#remove").click(function() {
t.removeRecord($("#remove-index").val());
});
}
// global just so I can inspect from the console
var t;
var rowNum = 0;
$(document).ready(function() {
setupClickHandlers();
var rows = getRows(100000);
var start = new Date().getTime();
t = new TilavaTable({
parent: $('#transactionTable tbody'),
template: $('#transactionTable tbody .template'),
render: function(row, record, index) {
row.find(".time").text(record.time);
row.find(".transactionId").text(record.transactionId);
row.find(".category").text(record.category);
row.find(".price").text("$" + record.price);
row.find(".quantity").text(record.quantity);
if (index % 2 == 0) {
row.addClass("even");
} else {
row.addClass("odd");
}
},
visibleRows: 10,
displayReversed: false
});
t.appendRecords(rows);
var end = new Date().getTime();
console.log("time to render (ms): ", end-start);
});
</script>
</head>
<body>
<h1>Tilava Table Example</h1>
<div>
<button id="clear">Clear Table</button><br/>
<button id="append-100k">Append 100k rows</button><br/>
<button id="append-1">Append row</button><br/>
<button id="prepend-100k">Prepend 100k rows</button><br/>
<button id="prepend-1">Prepend row</button><br/>
<button id="insert">Insert row</button><label for="insert-index"> @ Index </label><input id="insert-index" type="text" size="7" value="0"/><br/>
<button id="remove">Remove row</button><label for="remove-index"> @ Index </label><input id="remove-index" type="text" size="7" value="0"/><br/>
<br/>
</div>
<p>Example for displaying e-commerce transactions:</p>
<div>
<table id="transactionTable" >
<thead>
<tr>
<th>Time</th>
<th>Transaction Id</th>
<th>Category</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr class="template">
<td><span class="time"></span></td>
<td><span class="transactionId"></span></td>
<td><span class="category"></span></td>
<td><span class="price"></span></td>
<td><span class="quantity"></span></td>
</tr>
</tbody>
</table>
</div>
<p>
<a href="tutorial.html">See the tutorial</a>
</p>
</body>
</html>