100 | Pure AngularJs TreeView
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 | 112 |
113 |
Implementation steps
114 |115 |
Step 1: Install ADM-treeView
116 | 117 |
118 | npm install adm-trv
119 | bower install adm-trv
120 |
121 |
122 | Step 2: Include the files in your app
123 | 124 |
125 | <!doctype html>
126 | <html ng-app="myApp">
127 | <head>
128 | <link rel="stylesheet" href="css/ADM-treeView.min.css" />
129 | <script src="js/angular.min.js"></script>
130 | <script src="js/ADM-treeView.min.js"></script>
131 | ...
132 | </head>
133 | <body>
134 | ...
135 | </body>
136 | </html>
137 |
138 |
139 | Step 3: Inject the ADM-treeView module
140 | 141 |
142 | var app = angular.module('myApp', ['ADM-treeView']);
143 |
144 |
145 | Step 4: Add the adm-trv directive to a DOM element
146 | 147 |
148 | <adm-trv ng-model="model"></adm-trv>
149 |
150 | 151 |
Options
152 |153 |
Set options for entire of app
154 | 155 |
156 | app.config(['ADMtrvProvider', function(ADMtrv) {
157 | ADMtrv.setConfigs({
158 | childName: 'kids',
159 | title: '$item.mainDS.title',
160 | trackBy: '$item.mainDS.id',
161 | dictionary: {
162 | noItem: ' :( '
163 | },
164 | ...
165 | });
166 | }]);
167 |
168 |
169 | Set options for each directive
170 |
171 | <!-- pass options from controller -->
172 | <adm-trv ng-model="ctrl.model1" configs="tree1Options"></adm-trv>
173 | <!-- or write them inline -->
174 | <adm-trv ng-model="ctrl.model1" configs="{childName: 'levels', readOnly: true}"></adm-trv>
175 |
176 |
177 | Example:
179 |tree1Options
{{ tree1Options | json}}
ctrl.model1
{{ctrl.model1 || [] | json}}
{childName: 'levels', readOnly: true}
{{ {childName: 'levels', readOnly: true} | json}}
192 |
Quick look
193 | 194 |Name | 199 |Type | 200 |Default | 201 |Description | 202 |
---|---|---|---|
{{item.name}} | 207 |{{item.type}} | 208 |{{item.default}} | 209 |210 | |
216 |
onKidOpen event
217 |218 | In readOnly mode 'onKidOpen' event fire whenever the tree leafs clicked! You can return HTML content directly or by promise to show under leaf. 219 |
220 |
221 |
222 | // return string
223 | $scope.tree2_2Options = {
224 | childName: 'categories',
225 | readOnly: true,
226 | onKidOpen: function(node) {
227 | return 'The Node title is: "' + node.title + '"';
228 | }
229 | }
230 |
231 | // return promise
232 | $scope.tree2_2Options = {
233 | childName: 'categories',
234 | readOnly: true,
235 | onKidOpen: function(node) {
236 | var deferred = $q.defer();
237 | setTimeout(function() {
238 | deferred.resolve('The Node title is: "' + node.title + '"');
239 | }, 2000);
240 | return deferred.promise;
241 | }
242 | }
243 |
244 |
245 | Example:
247 |tree2Options
{{ tree2Options | json}}
ctrl.model1
{{ctrl.model2 || [] | json}}
tree2_2Options
256 | { 257 | childName: 'categories', 258 | readOnly: true, 259 | onKidOpen: function(node) { 260 | var deferred = $q.defer(); 261 | setTimeout(function() { 262 | deferred.resolve('The Node title is: "' + node.title + '"'); 263 | }, 2000); 264 | return deferred.promise; 265 | } 266 | } 267 |
273 |
onAdd event
274 |275 | The 'onAdd' event fire on adding item to tree.
276 | In case you want to post each node to server on add event, you can return promise to adm-trv to add node after server response.
277 | Return value can be 'Object' or 'Boolean'.
278 |
-
279 |
- 280 | Boolean: adm-trv continue adding node to tree by catching 'true' value. 281 | 282 |
- 283 | Object: In case server add 'Id' to your object after inserting to DB, that might be need for further editing or deleting, adm-trv will extend client object with your returned object. Return false to avoid adding node to tree. 284 | 285 |
287 |
288 |
289 | // return Booelan
290 | $scope.tree3_1Options = {
291 | childName: 'organizations',
292 | dictionary: {
293 | titlePlaceholder: 'A-Z only ...'
294 | },
295 | onAdd: function(parentNode, newNode, titleOnly) {
296 | return !/[^a-zA-Z]/.test(titleOnly);
297 | }
298 | }
299 |
300 | //return promise
301 | $scope.tree3_2Options = {
302 | childName: 'organizations',
303 | onAdd: function(parentNode, newNode, titleOnly) {
304 | var deferred = $q.defer();
305 | setTimeout(function() {
306 | deferred.resolve({
307 | id: Math.floor(Math.random() * 1000)
308 | });
309 | }, 500);
310 | return deferred.promise;
311 | }
312 | }
313 |
314 |
315 | Example:
317 |tree3_1Options
321 | { 322 | childName: 'organizations', 323 | dictionary: { 324 | titlePlaceholder: 'A-Z only ...' 325 | }, 326 | onAdd: function(parentNode, newNode, titleOnly) { 327 | return !/[^a-zA-Z]/.test(titleOnly); 328 | } 329 | } 330 |
ctrl.model3_1
{{ctrl.model3_1 || [] | json}}
tree3_2Options
336 | { 337 | childName: 'organizations', 338 | onAdd: function(parentNode, newNode, titleOnly) { 339 | var deferred = $q.defer(); 340 | setTimeout(function() { 341 | deferred.resolve({ 342 | id: Math.floor(Math.random() * 1000) 343 | }); 344 | }, 500); 345 | return deferred.promise; 346 | } 347 | } 348 |
ctrl.model3_2
{{ctrl.model3_2 || [] | json}}
356 |
onEdit & onDelete events
357 |358 |
359 |
360 | // return Booelan
361 | $scope.tree4_1Options = {
362 | onEdit: function (currentNode, parentNode) {
363 | return true; // or False
364 | },
365 | onDelete: function (currentNode, parentNode) {
366 | return true; // or False
367 | }
368 | }
369 |
370 |
371 | //return promise
372 | $scope.tree4_2Options = {
373 | onEdit: function (currentNode, parentNode) {
374 | var deferred = $q.defer();
375 | setTimeout(function() {
376 | deferred.resolve(true); // or False
377 | }, 500);
378 | return deferred.promise;
379 | },
380 | onDelete: function (currentNode, parentNode) {
381 | var deferred = $q.defer();
382 | setTimeout(function() {
383 | deferred.resolve(true); // or False
384 | }, 500);
385 | return deferred.promise;
386 | }
387 | }
388 |
389 |
390 |
391 | 392 |
Selectable
393 |394 |
395 |
396 | <adm-trv ng-model="ctrl.model4_1" selected="ctrl.model4_1Selected" configs="tree4_1Options"></adm-trv>
397 | <adm-trv ng-model="ctrl.model4_2" selected="ctrl.model4_2Selected" configs="tree4_2Options"></adm-trv>
398 |
399 |
400 | $scope.ctrl.model4_1Selected = [];
401 | $scope.tree4_1Options = {
402 | childName: 'bAghAlies',
403 | selectable: true
404 | }
405 |
406 | $scope.ctrl.model4_2Selected = [];
407 | $scope.tree4_2Options = {
408 | childName: 'bAghAlies',
409 | title: '$item.mainBAghAliDS.title',
410 | trackBy: '$item.mainBAghAliDS.id',
411 | selectable: true
412 | }
413 |
414 |
415 |
416 | Example:
418 |ctrl.model4_1Selected
{{ctrl.model4_1Selected | json}}
tree4_1Options
{{ tree4_1Options | json}}
ctrl.model4_1
{{ctrl.model4_1 | json}}
ctrl.model4_2Selected
{{ctrl.model4_2Selected | json}}
tree4_2Options
{{ tree4_2Options | json}}
ctrl.model4_2
{{ctrl.model4_2 | json}}
437 |
Dictionary
438 |439 |
440 |
441 | $scope.tree5_1Options = {
442 | childName: 'golAbies',
443 | dictionary: {
444 | noItem: 'No golAbi! :(',
445 | titlePlaceholder: 'Type ...',
446 | rootAddBtn: 'Add main golAbi',
447 | confirmBtn: 'YES',
448 | cancelBtn: 'NO'
449 | }
450 | }
451 |
452 | $scope.tree5_2Options = {
453 | childName: 'golAbies',
454 | direction: 'rtl',
455 | dictionary: {
456 | noItem: 'موردی وجود ندارد!',
457 | titlePlaceholder: 'عنوان ...',
458 | rootAddBtn: 'افزودن',
459 | confirmBtn: 'تایید',
460 | cancelBtn: 'انصراف'
461 | }
462 | }
463 |
464 |
465 |
466 | Example:
468 |480 | 481 | 487 | 488 |