-
Notifications
You must be signed in to change notification settings - Fork 77
/
treegrid.html
284 lines (274 loc) · 8.98 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
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
<html>
<head>
<title>jstree treegrid 3.2.0 plugin demo</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" />
<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.3.2/jstree.min.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",spanclass:"root"},
children: [
{text: "Really long named child whose name gets cut off", data: {price: "$4.00", size: "3",spanclass:"first"}},
{text: "Child 2", data: {price: "$8.00", size: "2",spanclass:"second"}, children:[
{text:"Grandchild",data:{price: "EXPENSIVE!",size:"10",spanclass:"third"}}
]}
]
}];
$("div#jstree").bind("loaded_grid.jstree",function(){
$("span#status").text("loaded");
}).on("select_cell.jstree-grid",function (e,data) {
$("span#clicked").html("clicked "+data.column+" of value "+data.value);
}).on('update_cell.jstree-grid',function (e,data) {
$("span#changed").html("changed "+data.col+" from "+data.old+" to "+data.value);
});
$("div#jstree").jstree({
plugins: ["themes","json","grid","dnd","contextmenu","search","sort"],
core: {
data: data
},
grid: {
columns: [
{width: 110, header: "Nodes",title:"_DATA_"},
{width: 110, cellClass: "col1", value: "price", header: "<i>Price</i>", title:"price", valueClass:"spanclass"},
{width: 110, cellClass: "col2", value: "size", header: "Qty", title:"size",valueClass:"spanclass"}
],
resizable:true,
draggable:true,
contextmenu:true,
gridcontextmenu: function (grid,tree,node,val,col,t,target)
{
return {
"edit": {
label: "Change value",
icon: "glyphicon glyphicon-pencil",
"action": function (data) {
var obj = t.get_node(node);
grid._edit(obj,col,target);
}
}
}
},
width: 306,
height: 100
},
dnd: {
drop_finish : function () {
},
drag_finish : function () {
},
drag_check : function (data) {
return {
after : true,
before : true,
inside : true
};
}
}
})
.on('loaded.jstree', function() {
$("div#jstree").jstree('open_all');
});
$("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);
});
$("input#search").keyup(function (e) {
var tree = $("div#jstree").jstree();
tree.search($(this).val());
});
// 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.data ? node.data.price : "");
}, width: 60, header: "Price", title:"price"},
{cellClass: "col2", value: function (node) {
return(node.data ? node.data.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
};
}
}
});
$("div#jstree5div").jstree({
plugins: ["themes","json","grid","dnd","contextmenu"],
core: {
data: data
},
grid: {
columns: [
{cellClass: "col1", value: "price", width: 60, header: "<i>Price</i>", title:"price"},
{width: 110, header: "Nodes",title:"_DATA_",tree:true},
{cellClass: "col2", value: "size", header: "Qty", title:"size"}
],
resizable:true,
contextmenu: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.2.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 and draggable columns set to true, as well as contextmenu enabled.</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>
<li>The fifth tree has 3 columns, but puts the tree in a different column.</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>Search <input type="text" id="search"></input></div>
<div>Click a cell to see results: <span id="clicked"></span></div>
<div>Right-click a cell and edit to see results: <span id="changed"></span></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>
<div id="jstree5">
<h4>Fifth Tree</h4>
<div id="jstree5div" style="max-height: 30px;"></div>
<div>Tree grid is <span id="fivestatus">loading</span>.</div>
</div>
</body>
</html>