-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathindex.html
More file actions
373 lines (351 loc) · 9.36 KB
/
index.html
File metadata and controls
373 lines (351 loc) · 9.36 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>sortable test</title>
<link rel="stylesheet" type="text/css" href="src/scss/example.scss" />
<link href="https://cdn.jsdelivr.net/gh/tofsjonas/searchable@latest/dist/searchable.min.css" rel="stylesheet" />
</head>
<body>
<h1>Sortable examples</h1>
<h2>Basic sort</h2>
<table class="sortable">
<thead>
<tr>
<th><span>Role</span></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>Rick</td>
</tr>
<tr>
<td><a href="javascript:alert('Inline javascript works!');">Sidekick</a></td>
<td><a id="morty" href="#">Morty</a></td>
</tr>
</tbody>
</table>
<h2>Tiebreaker</h2>
<p>Sort by year</p>
(Appearance manually changed using style attributes. Just for demonstration.)
<pre style="background: #ddd; width: 180px; padding: 0.5em; border-radius: 0.5em; color: #000">
style="
--stripe-bg: #ff0;
--stripe-color: #000;
--stripe-bg-odd: #f0f;
--stripe-color-odd: #111;
--th-bg: blue;
--th-color: #fff;"</pre
>
<table
class="sortable"
style="
--stripe-bg: #ff0;
--stripe-color: #000;
--stripe-bg-odd: #f0f;
--stripe-color-odd: #111;
--th-bg: blue;
--th-color: #fff;
"
>
<thead>
<tr>
<th data-sort-tbr="2">Month</th>
<th data-sort-tbr="0">Year</th>
<th data-sort-tbr="3">Day</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<tr>
<td>11</td>
<td>2010</td>
<td>25</td>
<td>12:00</td>
</tr>
<tr>
<td>11</td>
<td>2010</td>
<td>25</td>
<td>15:00</td>
</tr>
<tr>
<td>04</td>
<td>2010</td>
<td>12</td>
<td>13:00</td>
</tr>
</tbody>
</table>
<ul style="padding-left: 1.5em; font-style: italic">
<li>If year is the same, sort by month.</li>
<li>If month is the same, sort by day.</li>
<li>If day is the same, sort by time</li>
</ul>
<h2>Colspans</h2>
<table class="sortable sticky">
<thead>
<tr>
<th colspan="2">nums + chars</th>
<th data-sort-col="2">CHARS</th>
</tr>
</thead>
<tbody>
<tr>
<td>333</td>
<td>222</td>
<td>BB</td>
</tr>
<tr>
<td>1</td>
<td>111</td>
<td>CCC</td>
</tr>
<tr>
<td>22</td>
<td>333</td>
<td>A</td>
</tr>
</tbody>
</table>
<h2>Empty/null sorted last</h2>
<table class="sortable n-last lefty">
<thead>
<tr>
<th>Text</th>
<th class="indicator-left">Number</th>
</tr>
</thead>
<tbody>
<tr>
<td>jkl</td>
<td>0.4</td>
</tr>
<tr>
<td>abc</td>
<td>0</td>
</tr>
<tr>
<td>should be sorted last</td>
<td data-sort="">(if click in this column)</td>
</tr>
<tr>
<td>def</td>
<td>0.2</td>
</tr>
</tbody>
</table>
<h2>class="no-sort"</h2>
<table class="sortable">
<thead>
<tr>
<th>Role</th>
<th class="no-sort">Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>Rick</td>
</tr>
<tr>
<td>Sidekick</td>
<td>Morty</td>
</tr>
</tbody>
</table>
<h2>numeric sorting</h2>
<table class="sortable">
<thead>
<tr>
<th>Role</th>
<th>Time</th>
<th>Amount</th>
<th>Number</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>12:00:12</td>
<td>$18.49</td>
<td>2.49</td>
</tr>
<tr>
<td>Sidekick</td>
<td>12:22:11</td>
<td>$2.49</td>
<td>18.49</td>
</tr>
<tr>
<td>Butler</td>
<td>12:22:05</td>
<td>$1.96</td>
<td>1.96</td>
</tr>
</tbody>
</table>
<h2>Ascending sort</h2>
<table class="sortable asc">
<thead>
<tr>
<th><span>Role</span></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>Rick</td>
</tr>
<tr>
<td><a href="javascript:alert('Inline javascript works!');">Sidekick</a></td>
<td><a id="morty" href="#">Morty</a></td>
</tr>
</tbody>
</table>
<h2>Alternative sort</h2>
<table class="sortable">
<thead>
<tr>
<th>Movie Name</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<tr>
<td data-sort-alt="c" data-sort="a">A</td>
<td data-sort-alt="b" data-sort="c">B</td>
</tr>
<tr>
<td data-sort-alt="e" data-sort="f">D</td>
<td data-sort-alt="f" data-sort="a">E</td>
</tr>
<tr>
<td data-sort-alt="k" data-sort="b">J</td>
<td data-sort-alt="j" data-sort="h">K</td>
</tr>
</tbody>
</table>
<h2>TR element with no TD element (invalid HTML)</h2>
<table class="sortable">
<thead>
<tr>
<th>Letters</th>
</tr>
</thead>
<tbody>
<tr>
<td>CCC</td>
</tr>
<tr></tr>
<!-- TR element has no child TD elements -->
<tr>
<td>DDD</td>
</tr>
<tr>
<td>AAA</td>
</tr>
</tbody>
</table>
<h2>TD with "incorrect" whitespace</h2>
<table class="sortable">
<thead>
<tr>
<th>Role</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>Rick</td>
</tr>
<tr>
<td> Sidekick</td>
<td>Morty</td>
</tr>
</tbody>
</table>
<h2>HTML Tag Support</h2>
<table class="sortable">
<thead>
<tr>
<th>Event</th>
<th>Date</th>
<th>Progress</th>
<th>Score</th>
<th>Abbreviation</th>
</tr>
</thead>
<tbody>
<tr>
<td>Meeting</td>
<td><time datetime="2024-03-15">March 15, 2024</time></td>
<td><progress value="75" max="100">75%</progress></td>
<td><meter value="8.5" min="0" max="10">8.5/10</meter></td>
<td><abbr title="World Wide Web">WWW</abbr></td>
</tr>
<tr>
<td>Conference</td>
<td><time datetime="2024-01-10">January 10, 2024</time></td>
<td><progress value="50" max="100">50%</progress></td>
<td><meter value="9.2" min="0" max="10">9.2/10</meter></td>
<td><abbr title="Application Programming Interface">API</abbr></td>
</tr>
<tr>
<td>Workshop</td>
<td><time datetime="2024-12-01">December 1, 2024</time></td>
<td><progress value="90" max="100">90%</progress></td>
<td><meter value="7.8" min="0" max="10">7.8/10</meter></td>
<td><abbr title="Hypertext Markup Language">HTML</abbr></td>
</tr>
<tr>
<td>Seminar</td>
<td><time datetime="2024-06-20">June 20, 2024</time></td>
<td><progress max="100">Unknown</progress></td>
<td><data value="6.5">Six point five</data></td>
<td><abbr title="Cascading Style Sheets">CSS</abbr></td>
</tr>
</tbody>
</table>
<script>
document.getElementById('morty').addEventListener('click', function (e) {
e.preventDefault()
alert('event listeners also work!')
})
// Add a table, so we can test the MutationObserver
setTimeout(() => {
const table = document.createElement('table')
table.classList.add('sortable')
table.classList.add('searchable')
table.innerHTML = `
<thead>
<tr>
<th aria-sort="ascending">Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr><td>John Doe</td><td>30</td></tr>
<tr><td>Jane Smith</td><td>25</td></tr>
</tbody>
`
const div = document.createElement('div')
div.innerHTML = `<h2>MutationObserver Test</h2>
<p>This table was added using setTimeout. It will be sorted by default when using the <b>sortable.auto.js</b> package.</p>
<p>Just for fun we made it <a href="https://github.com/tofsjonas/searchable">searchable</a> also.</p>`
document.body.insertBefore(div, document.body.firstChild)
// If I append the the table to the div before appending it to the body,
// the MutationObserver will not trigger, since we are adding a div, not a table..
div.appendChild(table)
}, 2000) // Long delay so you can see the table being added
</script>
<script src="https://cdn.jsdelivr.net/gh/tofsjonas/searchable@latest/dist/searchable.min.js"></script>
<script type="module" src="/src/sortable.auto.ts"></script>
</body>
</html>