forked from deitch/jstree-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
treegrid.html
217 lines (206 loc) · 6.53 KB
/
treegrid.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
<html>
<head>
<title>jstree treegrid 3.0.0 plugin demo</title>
<link rel="stylesheet" href="lib/themes-3/default/style.min.css" />
<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type="text/javascript" src="lib/jstree-3.0.0.js"></script>
<script type="text/javascript" src="jstreegrid.js"></script>
<style type="text/css">
@import url('http://getbootstrap.com/dist/css/bootstrap.css');
</style>
<script type="text/javascript">
$(document).ready(function(){
var data;
data = [{
text: "Root 1",
data: {price: "$5.00", size: "4"},
children: [
{text: "Really long named child whose name gets cut off", data: {price: "<b>$4.00</b>", size: "3"}},
{text: "Child 2", data: {price: "<i>$3.00</i>", size: "2"}}
]
}];
$("div#jstree").bind("loaded_grid.jstree",function(){
$("span#status").text("loaded");
});
$("div#jstree").jstree({
plugins: ["themes","json","grid","dnd"],
core: {
data: data
},
grid: {
columns: [
{width: 110, header: "Nodes",title:"_DATA_"},
{cellClass: "col1", value: "price", width: 60, header: "Price", title:"price"},
{cellClass: "col2", value: "size", header: "Qty", title:"size"}
],
resizable:true
},
dnd: {
drop_finish : function () {
},
drag_finish : function () {
},
drag_check : function (data) {
return {
after : true,
before : true,
inside : true
};
}
}
});
$("a#change").click(function(){
var tree = $("div#jstree").jstree(),
nodename = tree.get_node("#").children[0], node = tree.get_node(nodename),
val = parseInt(node.data.size);
node.data.size = node.data.size*2;
tree.trigger("change_node.jstree",nodename);
return(false);
});
$("a#refresh").click(function(){
var tree = $("div#jstree").jstree();
var data = [{
text: "Root 1",
data: {price: "$5.00", size: "4"}
}];
tree.settings.core.data = data;
tree.refresh();
return(false);
});
// Do the second tree
$("div#jstreex").bind("loaded_grid.jstree",function(){
$("span#xstatus").text("loaded");
});
$("div#jstreex").jstree({
plugins: ["themes","json","grid","dnd"],
core: {
data: data
},
grid: {
columns: [
{width: 110, header: "Nodes",title:"_DATA_"},
{cellClass: "col1", value: "price", width: 60, header: "Price", title:"price"},
{cellClass: "col2", value: "size", width: 60, header: "Qty", title:"size"}
]
},
dnd: {
drop_finish : function () {
},
drag_finish : function () {
},
drag_check : function (data) {
return {
after : true,
before : true,
inside : true
};
}
}
});
$("div#jstreec").bind("loaded_grid.jstree",function () {
$("span#cstatus").text("loaded")
});
$('div#jstreec').jstree({
plugins: ['grid', 'types'],
core: {
themes: {variant: 'small'},
data: [{
text: "Root",
type: "default",
state: {opened: true},
data: {column1: 'foo'},
children: [
{
text: 'Level1',
type: "default",
data: {column1: 'bar'}
}
]
}]
},
grid: {
columns: [
{header: 'Name' , width: 200},
{header: 'Column1' , width: 200, value: 'column1'}]
},
types : {
default: {
icon : "glyphicon glyphicon-folder-open"
}
}
});
$("div#jstreef").bind("loaded_grid.jstree",function(){
$("span#fstatus").text("loaded");
});
$("div#jstreef").jstree({
plugins: ["themes","json","grid","dnd"],
core: {
data: data
},
grid: {
columns: [
{width: 110, header: "Nodes",title:"_DATA_"},
{cellClass: "col1", value: function (node) {
return(node.price);
}, width: 60, header: "Price", title:"price"},
{cellClass: "col2", value: function (node) {
return(node.size)
}, width: 60, header: "Qty", title:"size"}
],
resizable:true
},
dnd: {
drop_finish : function () {
},
drag_finish : function () {
},
drag_check : function (data) {
return {
after : true,
before : true,
inside : true
};
}
}
});
});
</script>
</head>
<body>
<h2>Tree Grid 3.0.0 Demo</h2>
This page gives a demo for using the excellent <a href="http://www.jstree.com">jstree</a>, built on the
amazing <a href="http://jquery.com">jQuery</a> library, with a tree grid. The treegrid is implemented
as a standard jstree plugin. Simply include jquery and jstree, and the plugin library jstreegrid.js,
and include it as a plugin. Look at the source to this page to see how it is done.
<p/>
Some interesting feature usage. Check out the HTML and JS config to see the details:
<ul>
<li>The first tree has resizable columns, set to true.</li>
<li>The second tree has a max-height set to 30px, causing the tree itself - but not the headers - to scroll.</li>
<li>The third tree uses an alternate them and styling.</li>
<li>The fourth tree uses a function for the <i>value</i>.</li>
</ul>
<div id="jstree1">
<h4>First Tree</h4>
<div id="jstree"></div>
<div>Tree grid is <span id="status">loading</span>.</div>
<div><a href="#" id="change">Click here to double the root Qty</a></div>
<div><a href="#" id="refresh">Click here to refresh the tree</a></div>
</div>
<div id="jstree2">
<h4>Second Tree</h4>
<div id="jstreex" style="max-height: 30px;"></div>
<div>Tree grid is <span id="xstatus">loading</span>.</div>
</div>
<div id="jstree3">
<h4>Third Tree</h4>
<div id="jstreec" style="max-height: 30px;"></div>
<div>Tree grid is <span id="cstatus">loading</span>.</div>
</div>
<div id="jstree4">
<h4>Fourth Tree</h4>
<div id="jstreef" style="max-height: 30px;"></div>
<div>Tree grid is <span id="fstatus">loading</span>.</div>
</div>
</body>
</html>