-
Notifications
You must be signed in to change notification settings - Fork 32
/
example.html
57 lines (56 loc) · 1.79 KB
/
example.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
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
$('tr.header').click(function () {
toggleRowChildren($(this), 'header');
});
function toggleRowChildren(parentRowElement, parentClass) {
var childClass = parentRowElement.attr('id');
$('tr.'+childClass, parentRowElement.parent()).fadeToggle(0);
$('tr.'+childClass).each(function(){
if ($(this).hasClass(parentClass) && !$(this).hasClass('collapsed')) {
toggleRowChildren($(this), parentClass);
}
});
parentRowElement.toggleClass('collapsed');
}
});
</script>
</head>
<body>
<table class="table table-hover table-bordered">
<tr id="cat1" class="header">
<th>Cat1</th>
<th>Row</th>
</tr>
<tr class="cat1">
<td>data1</td>
<td>data2</td>
</tr>
<tr id="cat1a" class="header cat1">
<th>Cat1a</th>
<th>Row</th>
</tr>
<tr class="cat1a">
<td>data1</td>
<td>data2</td>
</tr>
<tr class="cat1a">
<td>data3</td>
<td>data4</td>
</tr>
<tr id="cat2" class="header">
<th>Cat2</th>
<th>Row</th>
</tr>
<tr class="cat2">
<td>data1</td>
<td>data2</td>
</tr>
</table>
</body>
</html>