forked from maxazan/jquery-treegrid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
476 lines (454 loc) · 18.4 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
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Treegrid jquery plugin</title>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="http://yandex.st/highlightjs/7.3/styles/default.min.css">
<link rel="stylesheet" href="css/jquery.treegrid.css">
<script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-43342702-1', 'maxazan.github.io');
ga('send', 'pageview');
</script>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="wrapper">
<ul class="download" style="float:right;">
<li><a href="https://github.com/maxazan/jquery-treegrid/zipball/master">Download <br><strong>ZIP File</strong></a></li>
<li><a href="https://github.com/maxazan/jquery-treegrid/tarball/master">Download <br><strong>TAR Ball</strong></a></li>
<li><a href="https://github.com/maxazan/jquery-treegrid">View On <br><strong>GitHub</strong></a></li>
</ul>
<h1>TreeGrid jQuery plugin</h1>
<h2>Features</h2>
<ul>
<li>Create TreeGrid from HTML table</li>
<li>Simple and flexible javascript</li>
<li>Compatible with bootstrap</li>
<li>Ability to save the state of the tree</li>
<li>Events support</li>
</ul>
<h2>Usage</h2>
<p>Step 1. Initialize plugin</p>
<pre><code>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.treegrid.js"></script>
<link rel="stylesheet" href="css/jquery.treegrid.css">
<script type="text/javascript">
$('.tree').treegrid();
</script></code></pre>
<p>Step 2. Make table</p>
<pre><code class="html">
<table class="tree">
<tr class="treegrid-1">
<td>Root node</td><td>Additional info</td>
</tr>
<tr class="treegrid-2 treegrid-parent-1">
<td>Node 1-1</td><td>Additional info</td>
</tr>
<tr class="treegrid-3 treegrid-parent-1">
<td>Node 1-2</td><td>Additional info</td>
</tr>
<tr class="treegrid-4 treegrid-parent-3">
<td>Node 1-2-1</td><td>Additional info</td>
</tr>
</table>
</code></pre>
<p>Step 3. See result</p>
<table class="tree">
<tr class="treegrid-1">
<td>Root node</td><td>Additional info</td>
</tr>
<tr class="treegrid-2 treegrid-parent-1">
<td>Node 1-1</td><td>Additional info</td>
</tr>
<tr class="treegrid-3 treegrid-parent-1">
<td>Node 1-2</td><td>Additional info</td>
</tr>
<tr class="treegrid-4 treegrid-parent-3">
<td>Node 1-2-1</td><td>Additional info</td>
</tr>
</table>
<h2>Other examples</h2>
<p><a href="examples/example-basic.html" target="_blank">Basic example</a></p>
<p><a href="examples/example-column.html" target="_blank">Tree on 2nd column example</a></p>
<p><a href="examples/example-save-state.html" target="_blank">Save state example</a></p>
<p><a href="examples/example-bootstrap-2.html" target="_blank">TreeGrid for bootstrap 2.x</a></p>
<p><a href="examples/example-bootstrap-3.html" target="_blank">TreeGrid for bootstrap 3.x</a></p>
<p><a href="examples/example-events.html" target="_blank">Events examples</a></p>
<p><a href="examples/example-huge.html" target="_blank">Big data example</a></p>
<h2>Configuration Settings</h2>
<h3>Settings</h3>
<table>
<tr><th>Parameter</th><th>Type</th><th>Default value</th><th>Description</th></tr>
<tr>
<td>treeColumn</td>
<td>Numeric</td>
<td>0</td>
<td>Number of column using for tree</td>
</tr>
<tr>
<td>initialState</td>
<td>String</td>
<td>expanded</td>
<td>Initial state of tree<br>
'expanded' - all nodes will be expanded<br>
'collapsed' - all nodes will be collapsed<br>
</td>
</tr>
<tr>
<td>saveState</td>
<td>Boolean</td>
<td>false</td>
<td>If true you can reload page and tree state was saved</td>
</tr>
<tr>
<td>saveStateMethod</td>
<td>String</td>
<td>cookie</td>
<td>
'cookie' - save state to cookie<br>
'hash' - save state to hash<br>
</td>
</tr>
<tr>
<td>saveStateName</td>
<td>String</td>
<td>tree-grid-state</td>
<td>
Name of cookie or hash to save state.
</td>
</tr>
<tr>
<td>expanderTemplate</td>
<td>String</td>
<td><span class="treegrid-expander"></span></td>
<td>HTML Element when you click on that will be collapse/expand branches</td>
</tr>
<tr>
<td>expanderExpandedClass</td>
<td>String</td>
<td>treegrid-expander-expanded</td>
<td>Class using for expander element when it expanded</td>
</tr>
<tr>
<td>expanderCollapsedClass</td>
<td>String</td>
<td>treegrid-expander-collapsed</td>
<td>Class using for expander element when it collapsed</td>
</tr>
<tr>
<td>indentTemplate</td>
<td>String</td>
<td><span class="treegrid-indent"></span></td>
<td>HTML Element that will be placed as padding, depending on the depth of nesting node</td>
</tr>
<tr>
<td>onCollapse</td>
<td>Function</td>
<td>null</td>
<td>Function, which will be executed when one of node will be collapsed</td>
</tr>
<tr>
<td>onExpand</td>
<td>Function</td>
<td>null</td>
<td>Function, which will be executed when one of node will be expanded</td>
</tr>
<tr>
<td>onChange</td>
<td>Function</td>
<td>null</td>
<td>Function, which will be executed when one of node will be expanded or collapsed</td>
</tr>
</table>
<h3>Public methods</h3>
<table>
<tr>
<th>Method name</th>
<th>Description</th>
<th>Example</th>
</tr>
<tr>
<td>getRootNodes</td>
<td>Returns the root branches</td>
<td>
<pre><code class="javascript">// Expand all root nodes
$('.tree').treegrid('getRootNodes').treegrid('expand');</code></pre>
</td>
</tr>
<tr>
<td>getNodeId</td>
<td>Return the id of node</td>
<td>
<pre><code class="javascript">if($('#node-2').treegrid('getNodeId')===2){
// Do something with node 2
};</code></pre>
</td>
</tr>
<tr>
<td>getParentNodeId</td>
<td>Return the id of parent node or null if node is root</td>
<td>
<pre><code class="javascript">if($('#node-2').treegrid('getParentNodeId')===2){
// Do something if parent node Id is 2
};</code></pre>
</td>
</tr>
<tr>
<td>getAllNodes</td>
<td>Return the all nodes of tree</td>
<td>
<pre><code class="javascript">// Find all nodes
$('#tree-1').treegrid('getAllNodes').each(function() {
if ($(this).treegrid("isLast")) {
//Do something with all last nodes
}
});
</code></pre>
</td>
</tr>
<tr>
<td>getParentNode</td>
<td>Return the parent node or null if node is root</td>
<td>
<pre><code class="javascript">// Expand parent node
$('#node-2').treegrid('getParentNode').treegrid('collapse');
</code></pre>
</td>
</tr>
<tr>
<td>getChildNodes</td>
<td>Return the child nodes or null if node is leaf</td>
<td>
<pre><code class="javascript">// Expand child nodes
$('#node-2').treegrid('getChildNodes').treegrid('expand');
</code></pre>
</td>
</tr>
<tr>
<td>getDepth</td>
<td>Returns the depth of nested branch</td>
<td>
<pre><code class="javascript">// Expand all nodes 2nd nesting
$('.tree').find('tr').each(function(){
if ($(this).treegrid('getDepth')<2){
$(this).treegrid('expand');
}
});</code></pre>
</td>
<tr>
<td>isNode</td>
<td>return true if element is node</td>
<td>
<pre><code class="javascript">
$('#tree-1').find('tr').each(function() {
if ($(this).treegrid("isNode")) {
//Do something
}
});
</code></pre>
</td>
</tr>
<tr>
<td>isLeaf</td>
<td>Is there a node leaf</td>
<td>
<pre><code class="javascript">// hide all files
$('.tree').find('tr').each(function(){
if ($(this).treegrid('isLeaf')){
$(this).hide();
}
});</code></pre>
</td>
</tr>
<tr>
<td>isLast</td>
<td>Return true if node is last in branch</td>
<td>
<pre><code class="javascript">// hide all last elements
$('.tree').find('tr').each(function(){
if ($(this).treegrid('isLast')){
$(this).hide();
}
});</code></pre>
</td>
</tr>
<tr>
<td>isFirst</td>
<td>Return true if node is first in branch</td>
<td>
<pre><code class="javascript">// hide all last elements
$('.tree').find('tr').each(function(){
if ($(this).treegrid('isFirst')){
$(this).hide();
}
});</code></pre>
</td>
</tr>
<tr>
<td>isExpanded</td>
<td>Is node expanded</td>
<td>
<pre><code class="javascript">if($('#node-2').treegrid('isExpanded')){
// Do something if node expanded
};</code></pre>
</td>
</tr>
<tr>
<td>isCollapsed</td>
<td>Is node collapsed</td>
<td>
<pre><code class="javascript">if($('#node-2').treegrid('isCollapsed')){
// Do something if node collapsed
};</code></pre>
</td>
</tr>
<tr>
<td>isOneOfParentsCollapsed</td>
<td>Is at least one of the parent nodes is collapsed</td>
<td>
<pre><code class="javascript">if($('#node-2').treegrid('isOneOfParentCollapsed')){
// Do something if one of parent collapsed
};</code></pre>
</td>
</tr>
<tr>
<td>expand</td>
<td>Expand node</td>
<td>
<pre><code class="javascript">$('#node-2').treegrid('expand');</code></pre>
</td>
</tr>
<tr>
<td>collapse</td>
<td>Collapse node</td>
<td>
<pre><code class="javascript">$('#node-2').treegrid('collapse');</code></pre>
</td>
</tr>
<tr>
<td>expandRecursive</td>
<td>Expand nodes recursively</td>
<td>
<pre><code class="javascript">$('#node-2').treegrid('expandRecursive');</code></pre>
</td>
</tr>
<tr>
<td>collapseRecursive</td>
<td>Collapse nodes recursively</td>
<td>
<pre><code class="javascript">$('#node-2').treegrid('collapseRecursive');</code></pre>
</td>
</tr>
<tr>
<td>expandAll</td>
<td>Expand all nodes</td>
<td>
<pre><code class="javascript">$('#tree').treegrid('expandAll');</code></pre>
</td>
</tr>
<tr>
<td>collapseAll</td>
<td>Collapse all nodes</td>
<td>
<pre><code class="javascript">$('#tree').treegrid('collapseAll');</code></pre>
</td>
</tr>
<tr>
<td>toggle</td>
<td>Collapse node if it expanded and expand when collapsed</td>
<td>
<pre><code class="javascript">$('#node-2').treegrid('toggle');</code></pre>
</td>
</tr>
<tr>
<td>render</td>
<td>Redraw the node and all its children</td>
<td>
<pre><code class="javascript">$('#node-2').treegrid('render');</code></pre>
</td>
</tr>
</table>
<h3>Events</h3>
<table>
<tr>
<th>Event name</th>
<th>Description</th>
<th>Example</th>
</tr>
<tr>
<td>collapse</td>
<td>Will fire when node collapsed</td>
<td>
<pre><code class="javascript">//Alert when node in treegrid with class "tree" collapsed
$('.tree').treegrid('getRootNodes').on('collapse', function(){
alert(this);
});</code></pre>
</td>
</tr>
<tr>
<td>expand</td>
<td>Will fire when node expanded</td>
<td>
<pre><code class="javascript">//Alert when node with id "node1" expanded
$('#node1').on('expand', function(){
alert(this);
});</code></pre>
</td>
</tr>
<tr>
<td>change</td>
<td>Will fire when node changed. Expanded or collapsed</td>
<td>
<pre><code class="javascript">//Alert when node in treegrid with class "tree" changed.
$('.tree').treegrid('getRootNodes').on('change', function(){
alert(this);
});</code></pre>
</td>
</tr>
</table>
<h2><a href="test.html">Unit Tests</a></h2>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.treegrid.min.js"></script>
<script type="text/javascript">
$('.tree').treegrid();
</script>
<script type="text/javascript">
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i = 0; i < metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
}
}
document.addEventListener("gesturestart", gestureStart, false);
}
function gestureStart() {
for (i = 0; i < metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
}
}
}</script>
</body>
</html>