forked from kylefox/jquery-tablesort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zepto.html
145 lines (131 loc) · 2.67 KB
/
zepto.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
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
145
<html>
<head>
<title></title>
<style type="text/css">
body {
font: normal 14px/21px Arial, serif;
}
.example {
float: left;
width: 40%;
margin: 5%;
}
table {
font-size: 1em;
border-collapse: collapse;
margin: 0 auto
}
table, th, td {
border: 1px solid #999;
padding: 8px 16px;
text-align: left;
}
th {
background: #f4f4f4;
cursor: pointer;
}
th:hover,
th.sorted {
background: #d4d4d4;
}
th.sorted.ascending:after {
content: " \2191";
}
th.sorted.descending:after {
content: " \2193";
}
</style>
</head>
<body>
<div class="example ex-1">
<table>
<thead>
<tr>
<th>Name</th>
<th>Band</th>
<th>Date of Birth</th>
<th class="number">Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>Thom Yorke</td>
<td>Radiohead</td>
<td data-sort-value="2">October 7, 1968</td>
<td>43</td>
</tr>
<tr>
<td>Justin Vernon</td>
<td>Bon Iver</td>
<td data-sort-value="4">April 30, 1981</td>
<td>30</td>
</tr>
<tr>
<td>Paul McCartney</td>
<td>The Beatles</td>
<td data-sort-value="1">June 18, 1942</td>
<td>69</td>
</tr>
<tr>
<td>Sam Beam</td>
<td>Iron & Wine</td>
<td data-sort-value="3">July 26, 1974</td>
<td>37</td>
</tr>
</tbody>
</table>
<p>No <code>thead</code> or <code>tbody</code>; just <code>tr</code>s</p>
<table>
<tr>
<th>Name</th>
<th>Band</th>
<th>Date of Birth</th>
<th class="number">Age</th>
</tr>
<tr>
<td>Thom Yorke</td>
<td>Radiohead</td>
<td data-sort-value="2">October 7, 1968</td>
<td>43</td>
</tr>
<tr>
<td>Justin Vernon</td>
<td>Bon Iver</td>
<td data-sort-value="4">April 30, 1981</td>
<td>30</td>
</tr>
<tr>
<td>Paul McCartney</td>
<td>The Beatles</td>
<td data-sort-value="1">June 18, 1942</td>
<td>69</td>
</tr>
<tr>
<td>Sam Beam</td>
<td>Iron & Wine</td>
<td data-sort-value="3">July 26, 1974</td>
<td>37</td>
</tr>
</table>
</div>
<div class="example ex-2"></div>
<script src="http://f.cl.ly/items/2Q3A1w0X3p0q2N2f103B/zepto.js"></script>
<script src="jquery.tablesort.js"></script>
<script type="text/javascript">
$(function() {
var table = $('<table></table>');
table.append('<thead><tr><th class="number">Number</th></tr></thead>');
var tbody = $('<tbody></tbody>');
for(var i = 0; i<100; i++) {
tbody.append('<tr><td>' + Math.floor(Math.random() * 100) + '</td></tr>');
}
table.append(tbody);
$('.example.ex-2').append(table);
$('table').tablesort().data('tablesort');
$('thead th.number').data('sortBy', function(th, td, sorter) {
return parseInt(td.text(), 10);
});
});
</script>
</body>
</html>