forked from kylefox/jquery-tablesort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
143 lines (125 loc) · 2.94 KB
/
index.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
<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;
}
table.ex-2 {
min-width: 100px;
}
th {
background: #f4f4f4;
cursor: pointer;
}
th:hover,
th.sorted {
background: #d4d4d4;
}
th.no-sort,
th.no-sort:hover {
background: #f4f4f4;
cursor: not-allowed;
}
th.sorted.ascending:after {
content: " \2191";
}
th.sorted.descending:after {
content: " \2193";
}
.disabled {
opacity: 0.5;
}
</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>
<th class="no-sort">Photo</th>
</tr>
</thead>
<tbody>
<tr>
<td>Thom Yorke</td>
<td>Radiohead</td>
<td data-sort-value="2">October 7, 1968</td>
<td>43</td>
<td><img src="http://place-hoff.com/100/100" width="50"></td>
</tr>
<tr>
<td>Justin Vernon</td>
<td>Bon Iver</td>
<td data-sort-value="4">April 30, 1981</td>
<td>30</td>
<th><img src="http://www.fillmurray.com/100/100" width="50"></td>
</tr>
<tr>
<td>Paul McCartney</td>
<td>The Beatles</td>
<td data-sort-value="1">June 18, 1942</td>
<td>69</td>
<td><img src="https://www.placecage.com/100/100" width="50"></td>
</tr>
<tr>
<td>Sam Beam</td>
<td>Iron & Wine</td>
<td data-sort-value="3">July 26, 1974</td>
<td>37</td>
<td><img src="http://www.stevensegallery.com/200/200" width="50"></td>
</tr>
</tbody>
</table>
</div>
<div class="example ex-2">
<div id="sort-msg" style="float: right;" />
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="jquery.tablesort.min.js"></script>
<script type="text/javascript">
$(function() {
var table = $('<table class="ex-2"></table>');
table.append('<thead><tr><th class="number">Number</th></tr></thead>');
var tbody = $('<tbody></tbody>');
for(var i = 0; i<500; 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);
});
//Sorting indicator example
$('table.ex-2').on('tablesort:start', function(event, tablesort) {
$('table.ex-2 tbody').addClass("disabled");
$('.ex-2 th.number').removeClass("sorted").text('Sorting..');
});
$('table.ex-2').on('tablesort:complete', function(event, tablesort) {
$('table.ex-2 tbody').removeClass("disabled");
$('.ex-2 th.number').text('Number');
});
});
</script>
</body>
</html>