-
Notifications
You must be signed in to change notification settings - Fork 26
/
treetable.html
101 lines (100 loc) · 3.65 KB
/
treetable.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
<html>
<head>
<title>jstree-table plugin demo</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.2/css/font-awesome.min.css" rel="stylesheet">
<script type='text/javascript' src='http://code.jquery.com/jquery-2.1.0.js'></script>
<script type='text/javascript' src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<script type="text/javascript" src="jstreetable.js"></script>
<style type="text/css">
@import url('http://getbootstrap.com/dist/css/bootstrap.css');
body {
margin: 1em;
}
.jstree-table-wrapper {
border: 1px solid #ccc;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
// tree data
var data = [{
id: "Products",
text: "Products",
data: {},
children: [{
id: "Fruit",
text: "Fruit",
data: {},
children:[
{id: "Apple", text: "Apple", data: {price: 0.1, quantity: 20}},
{id: "Banana", text: "Banana", data: {price: 0.2, quantity: 31}},
{id: "Grapes", text: "Grapes", data: {price: 1.99, quantity: 34}},
{id: "Mango", text: "Mango", data: {price: 0.5, quantity: 8}},
{id: "Melon", text: "Melon", data: {price: 0.8, quantity: 4}},
{id: "Pear", text: "Pear", data: {price: 0.1, quantity: 30}},
{id: "Strawberry", text: "Strawberry", data: {price: 0.15, quantity: 32}}
],
'state': {'opened': true}
}, {
id: "Vegetables",
text: "Vegetables",
data: {},
children:[
{id: "Aubergine", text: "Aubergine", data: {price: 0.5, quantity: 8}},
{id: "Broccoli", text: "Broccoli", data: {price: 0.4, quantity: 22}},
{id: "Carrot", text: "Carrot", data: {price: 0.1, quantity: 32}},
{id: "Cauliflower", text: "Cauliflower", data: {price: 0.45, quantity: 18}},
{id: "Potato", text: "Potato", data: {price: 0.2, quantity: 38}}
]
}],
'state': {'opened': true}
}];
// load jstree
$("div#jstree").jstree({
plugins: ["table","dnd","contextmenu","sort"],
core: {
data: data,
check_callback: true
},
// configure tree table
table: {
columns: [
{width: 200, header: "Name"},
{width: 150, value: "price", header: "Price", format: function(v) {if (v){ return '$'+v.toFixed(2) }}},
{width: 150, value: "quantity", header: "Qty"}
],
resizable: true,
draggable: true,
contextmenu: true,
width: 500,
height: 200
}
});
});
</script>
</head>
<body>
<h2>JsTree Table Demo</h2>
This page gives a demo for using the excellent <a href="http://www.jstree.com">jstree</a> with a table.
The table is implemented as a standard jstree plugin.
Include jquery and jstree, and the plugin library jstreetable.js, and include it as a plugin.
Look at the source to this page to see how it is done.
<p>
This example demonstrates advanced features including:
</p>
<ul>
<li>Show / hide columns via context menu</li>
<li>Resizable columns</li>
<li>Column reordering</li>
<li>Draggable columns</li>
<li>Edit cells via context menu</li>
<li>Fixed height to enable scrolling</li>
<li>Cell formatting e.g. 10 => $10.00</li>
</ul>
<div id="jstree1">
<div id="jstree"></div>
</div>
</body>
</html>