forked from dojo/dojo1-dgrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.html
197 lines (180 loc) · 6.24 KB
/
tree.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Tree Grid</title>
<meta name="viewport" content="width=570">
<style>
@import "../../dojo/resources/dojo.css";
@import "../css/skins/claro.css";
.dgrid {
width: 700px;
}
.field-bool {
width: 4em;
}
#treeGrid .field-type {
width: 5em;
}
#treeSelector .selector {
width: 2em;
}
.ui-widget{
margin: 10px;
}
</style>
<script src="../../dojo/dojo.js"
data-dojo-config="async: true"></script>
<script>
require(["dojo/on", "dgrid/OnDemandGrid","dgrid/tree","dgrid/editor", "dgrid/Keyboard",
"dgrid/Selection", "dgrid/selector", "dgrid/ColumnSet",
"dojo/_base/declare", "dgrid/test/data/base", "dojo/domReady!"],
function(on, Grid, tree, editor, Keyboard, Selection, selector, ColumnSet, declare, testStore){
var count = 0; // for incrementing edits from button under 1st grid
function byId(id){
return document.getElementById(id);
}
function nbspFormatter(value){
// returns " " for blank content, to prevent cell collapsing
return value === undefined || value === "" ? " " : value;
}
var StandardGrid = declare([Grid, Keyboard, Selection]);
var treeGrid = window.treeGrid = new StandardGrid({
store: testCountryStore,
columns: [
tree({label: "Name", field:"name", sortable: false}),
editor({label: "Visited", field: "bool", sortable: false}, "checkbox"),
{label:"Type", field:"type", sortable: false},
{label:"Population", field:"population"},
{label:"Timezone", field:"timezone"}
]
}, "treeGrid");
on(byId("filter"), "click", function(){
treeGrid.set("query", { name: /a$/ });
});
on(byId("clearFilter"), "click", function(){
treeGrid.set("query", {});
});
on(byId("save"), "click", function(){
treeGrid.save();
});
on(byId("revert"), "click", function(){
treeGrid.revert();
});
on(byId("add-country"), "click", function(){
testCountryStore.put({ id: 'GR', name:'Greece', type:'country', parent: 'EU'});
});
on(byId("remove-country"), "click", function(){
testCountryStore.remove('GR');
});
on(byId("add-continent"), "click", function(){
testCountryStore.put({ id: 'NE', name:'My New Europe', type:'continent'});
testCountryStore.put({ id: 'NI', name:'My New Italy', type:'country', parent: 'NE'});
});
on(byId("delete"), "click", function(){
for(var id in treeGrid.selection){
console.log("id: ", id);
testCountryStore.remove(id);
}
});
on(byId("edit-continent"), "click", function(){
var item = testCountryStore.get("EU");
item.name = "Europe Edit " + (++count);
testCountryStore.put(item);
});
on(byId("move-rome-na"), "click", function(){
var item = testCountryStore.get("Rome");
item.parent = "NA";
testCountryStore.put(item);
});
function getTreeSelectorColumns(){
return [
selector({className: "selector"}),
tree({
label: "Name",
field: "name",
formatter: function(value){
return "<strong>" + value + "</strong>";
},
sortable: false
}),
editor({label: "Visited", field: "bool", sortable: false}, "checkbox"),
{label:"Type", field:"type", sortable: false},
{label:"Population", field:"population"},
{label:"Timezone", field:"timezone"}
];
}
window.treeSelector = new StandardGrid({
store: testCountryStore,
selectionMode: "none",
allowSelectAll: true,
columns: getTreeSelectorColumns()
}, "treeSelector");
// Test resetting column definition on this grid, since it exercises
// one of each type of OOTB column plugin.
on(byId("resetColumns"), "click", function(){
treeSelector.set("columns", getTreeSelectorColumns());
});
window.treeTopHeavy = new StandardGrid({
store: testTopHeavyStore,
query: { parent: undefined },
columns: {
abbreviation: tree({ label: "Abbreviation", field: "abbreviation" }),
name: "Name"
}
}, "treeTopHeavy");
window.treeSubRows = new StandardGrid({
store: testCountryStore,
subRows: [[
tree({label:"Name", field:"name", sortable: false}),
{label:"Type", field:"type", sortable: false}
], [
{label:"Population", field:"population"},
{label:"Timezone", field:"timezone"}
]]
}, "treeSubRows");
window.treeColumnSets = new (declare([Grid, Keyboard, Selection, ColumnSet]))({
store: testCountryStore,
columnSets: [[
[ tree({label:"Name", field:"name", sortable: false}) ],
[ {label:"Type", field:"type", sortable: false} ]
], [
[
{label:"Population", field:"population", formatter:nbspFormatter},
{label:"Timezone", field:"timezone", formatter:nbspFormatter}
], [
{label:"Area", field:"area", colSpan:2, formatter:nbspFormatter}
]
]]
}, "treeColumnSets");
});
</script>
</head>
<body class="claro">
<h2>Lazy-loading tree grid, with store functionality</h2>
<div id="treeGrid"></div>
<div>
<button id="filter">Show only entries ending in "a"</button>
<button id="clearFilter">Show all</button>
</div>
<div>
<button id="save">Save</button>
<button id="revert">Revert</button>
<button id="add-continent">Add Continent</button>
<button id="add-country">Add Greece To Europe</button>
<button id="remove-country">Remove Greece</button>
<button id="delete">Delete Selected</button>
<button id="edit-continent">Edit Europe</button>
<button id="move-rome-na">Move Rome to North America</button>
</div>
<h2>Tree grid with formatter on tree column, and a checkbox selector to test select-all on children</h2>
<div id="treeSelector"></div>
<button id="resetColumns">Reset Columns</button> (to test column.init/destroy)
<h2>Tree grid with more children than parents</h2>
<div id="treeTopHeavy"></div>
<h2>Tree grid with subRows</h2>
<div id="treeSubRows"></div>
<h2>Tree grid with columnSets</h2>
<div id="treeColumnSets"></div>
</body>
</html>