Newer
Older
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Fancytree - Example: Select</title>
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link href="../src/skin-win8/ui.fancytree.css" rel="stylesheet">
<script src="../src/jquery.fancytree.js"></script>
<!-- Start_Exclude: This block is not part of the sample code -->
<link href="../lib/prettify.css" rel="stylesheet">
<script src="../lib/prettify.js"></script>
<link href="sample.css" rel="stylesheet">
<script src="sample.js"></script>
<!-- End_Exclude -->
<style type="text/css">
</style>
<script type="text/javascript">
$(function(){
// --- Initialize sample trees
$("#tree1").fancytree({
checkbox: "radio",
selectMode: 1,
// tooltip: true,
// tooltip: function(event, data) { return data.node.title + "!"},
source: [
{title: "n1 (checkbox: false)", expanded: true, checkbox: false, children: [
{title: "n1.1"},
{title: "n1.2 (selected)", selected: true},
{title: "n1.3"}
]},
{title: "n2", expanded: true, checkbox: false, children: [
{title: "n2.1"},
{title: "n2.2"},
{title: "n2.3"}
]}
],
init: function(event, data) {
// Set key from first part of title (just for this demo output)
data.tree.visit(function(n) {
n.key = n.title.split(" ")[0];
});
},
activate: function(event, data) {
$("#echoActive1").text(data.node.title);
},
select: function(event, data) {
// Display list of selected nodes
var s = data.tree.getSelectedNodes().join(", ");
$("#echoSelection1").text(s);
}
});
// ---------------------------------------------------------------------
$("#btnDeselectAll2").click(function(){
$("#tree2").fancytree("getTree").visit(function(node){
node.setSelected(false);
});
return false;
});
$("#btnSelectAll2").click(function(){
$("#tree2").fancytree("getTree").visit(function(node){
node.setSelected(true);
});
return false;
});
$("#tree2").fancytree({
checkbox: true,
selectMode: 2,
source: [
{title: "n1 (selected)", expanded: true, selected: true, children: [
{title: "n1.1"},
{title: "n1.2 (selected)", selected: true},
{title: "n1.3"}
]},
{title: "n2 (checkbox: false)", expanded: true, checkbox: false, children: [
{title: "n2.1"},
{title: "n2.2"},
{title: "n2.3"}
]},
{title: "n3 (radiogroup, checkbox: false)", expanded: true,
checkbox: false, radiogroup: true, children: [
{title: "n3.1"},
{title: "n3.2"},
{title: "n3.3"}
]}
],
init: function(event, data) {
// Set key from first part of title (just for this demo output)
data.tree.visit(function(n) {
n.key = n.title.split(" ")[0];
});
},
select: function(event, data) {
// Display list of selected nodes
var selNodes = data.tree.getSelectedNodes();
// convert to title/key array
var selKeys = $.map(selNodes, function(node){
return "[" + node.key + "]: '" + node.title + "'";
});
$("#echoSelection2").text(selKeys.join(", "));
},
// The following options are only required, if we have more than one tree on one page:
cookieId: "fancytree-Cb2",
idPrefix: "fancytree-Cb2-"
});
// ---------------------------------------------------------------------
$("#btnDeselectAll3").click(function(){
$("#tree3").fancytree("getTree").visit(function(node){
node.setSelected(false);
});
return false;
});
$("#btnSelectAll3").click(function(){
$("#tree3").fancytree("getTree").visit(function(node){
node.setSelected(true);
});
return false;
});
$("#tree3").fancytree({
checkbox: true,
selectMode: 3,
source: [
{title: "n1", expanded: true, children: [
{title: "n1.1 (selected)"},
{title: "n1.2"},
{title: "n1.3"}
]},
{title: "n2", expanded: true, children: [
{title: "n2.1 (selected)", selected: true},
{title: "n2.2", selected: false},
{title: "n2.3", selected: null}
]},
{title: "n3", expanded: true, children: [
{title: "n3.1", expanded: true, children: [
{title: "n3.1.1 (unselectable)", unselectable: true},
{title: "n3.1.2 (unselectable)", unselectable: true},
{title: "n3.1.3"}
]},
{title: "n3.2", expanded: true, children: [
{title: "n3.2.1 (unselectableStatus: true)", unselectableStatus: true},
{title: "n3.2.2 (unselectableStatus: false)", unselectableStatus: false},
{title: "n3.2.3"}
]},
{title: "n3.3", expanded: true, children: [
{title: "n3.3.1 (unselectableStatus: true, unselectableIgnore)",
unselectableStatus: true, unselectableIgnore: true},
{title: "n3.3.2 (unselectableStatus: false, unselectableIgnore)",
unselectableStatus: false, unselectableIgnore: true},
{title: "n3.3.3"}
]}
]}
],
init: function(event, data) {
// Set key from first part of title (just for this demo output)
data.tree.visit(function(n) {
n.key = n.title.split(" ")[0];
n.expanded = true;
});
},
lazyLoad: function(event, ctx) {
ctx.result = {url: "ajax-sub2.json", debugDelay: 1000};
},
loadChildren: function(event, ctx) {
ctx.node.fixSelection3AfterClick();
},
select: function(event, data) {
// Get a list of all selected nodes, and convert to a key array:
var selKeys = $.map(data.tree.getSelectedNodes(), function(node){
return node.key;
});
$("#echoSelection3").text(selKeys.join(", "));
// Get a list of all selected TOP nodes
var selRootNodes = data.tree.getSelectedNodes(true);
// ... and convert to a key array:
var selRootKeys = $.map(selRootNodes, function(node){
return node.key;
});
$("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
// $("#echoSelectionRoots3").text(selRootNodes.join(", "));
},
// The following options are only required, if we have more than one tree on one page:
cookieId: "fancytree-Cb3",
idPrefix: "fancytree-Cb3-"
});
});
</script>
</head>
<body class="example">
<h1>Example: Selection and Checkboxes</h1>
<p class="description">
Use different select modes for the tree and distinct nodes.
</p>
<div>
<label for="skinswitcher">Skin:</label> <select id="skinswitcher"></select>
</div>
<!-- Tree #1 -->
<p class="description">
This tree has <b>checkoxes and selectMode 1 (single-selection)</b> enabled.<br>
The checkbox icons are replaced by radio buttons by adding
the <code>tree.checkbox: "radio"</code> option.
</p>
<div id="tree1">
</div>
<div>Active node: <span id="echoActive1">-</span></div>
<div>Selection: <span id="echoSelection1">-</span></div>
<!-- Tree #2 -->
<p class="description">
This tree has <b>selectMode 2 (multi-selection)</b> enabled.<br>
Node `n3` uses the 'radiogroup' option and hides the checkbox.
</p>
<p>
<a href="#" id="btnSelectAll2">Select all</a> -
<a href="#" id="btnDeselectAll2">Deselect all</a>
</p>
<div id="tree2"></div>
<div>Selected keys: <span id="echoSelection2">-</span></div>
<!-- Tree #3 -->
<p class="description">
This tree has <b>checkoxes and selectMode 3 (hierarchical multi-selection)</b> enabled.<br>
Node `n3` features different variations of the <code>unselectable</code> mode.
</p>
<p>
<a href="#" id="btnSelectAll3">Select all</a> -
<a href="#" id="btnDeselectAll3">Deselect all</a>
</p>
<div id="tree3"></div>
<div>Selected keys: <span id="echoSelection3">-</span></div>
<div>Selected root keys: <span id="echoSelectionRootKeys3">-</span></div>
<!-- <div>Selected root nodes: <span id="echoSelectionRoots3">-</span></div> -->
<!-- Start_Exclude: This block is not part of the sample code -->
<hr>
<p class="sample-links no_code">
<a class="hideInsideFS" href="https://github.com/mar10/fancytree">jquery.fancytree.js project home</a>
<a class="hideOutsideFS" href="#">Link to this page</a>
<a class="hideInsideFS" href="index.html">Example Browser</a>
<a href="#" id="codeExample">View source code</a>
</p>
<pre id="sourceCode" class="prettyprint" style="display:none"></pre>
<!-- End_Exclude -->
</body>
</html>