|
12 | 12 | - [tree](#tree) |
13 | 13 | - [[tree]](#tree) |
14 | 14 | - [Load children asynchronously](#load-children-asynchronously) |
| 15 | + - [Load children using ngrx (or any redux-like library)](#load-children-using-ngrx-or-any-redux-like-library) |
15 | 16 | - [Configure node via TreeModelSettings](#configure-node-via-treemodelsettings) |
16 | 17 | - [[settings]](#settings) |
17 | 18 | - [`Tree` class](#tree-class) |
|
23 | 24 | - [NodeRenamedEvent](#noderenamedevent) |
24 | 25 | - [NodeExpandedEvent](#nodeexpandedevent) |
25 | 26 | - [NodeCollapsedEvent](#nodecollapsedevent) |
| 27 | + - [LoadNextLevelEvent](#loadnextlevelevent) |
26 | 28 | - [:gun: Controller](#gun-controller) |
27 | | - - [select - selecting a node](#select---selecting-a-node) |
| 29 | + - [select - selects a node](#select---selects-a-node) |
28 | 30 | - [isSelected - checks whether a node is selected](#isselected---checks-whether-a-node-is-selected) |
29 | 31 | - [collapse - collapses a node](#collapse---collapses-a-node) |
30 | 32 | - [isCollapsed - check whether a node is collapsed](#iscollapsed---check-whether-a-node-is-collapsed) |
31 | 33 | - [expand - expands a node](#expand---expands-a-node) |
32 | | - - [isExpanded - checks wheather a node is expanded](#isexpanded---checks-wheather-a-node-is-expanded) |
| 34 | + - [isExpanded - checks whether a node is expanded](#isexpanded---checks-whether-a-node-is-expanded) |
33 | 35 | - [rename - renames a node (changes its value underneath)](#rename---renames-a-node-changes-its-value-underneath) |
| 36 | + - [startRenaming - changes the node template so that text input appears and lets a user type a new name](#startrenaming---changes-the-node-template-so-that-text-input-appears-and-lets-a-user-type-a-new-name) |
34 | 37 | - [remove - removes a node from the tree](#remove---removes-a-node-from-the-tree) |
35 | 38 | - [addChild - creates a new child node](#addchild---creates-a-new-child-node) |
36 | 39 | - [changeNodeId - changes node's id](#changenodeid---changes-nodes-id) |
37 | | - - [reloadChildren - load async children once more](#reloadchildren---load-async-children-once-more) |
| 40 | + - [reloadChildren - loads async children once more](#reloadchildren---loads-async-children-once-more) |
38 | 41 | - [setChildren - changes children of a node;](#setchildren---changes-children-of-a-node) |
39 | 42 | - [SystemJS](#systemjs) |
40 | 43 | - [Changes that should be taken into account in order to migrate from __ng2-tree V1__ to __ng2-tree V2__](#changes-that-should-be-taken-into-account-in-order-to-migrate-from-__ng2-tree-v1__-to-__ng2-tree-v2__) |
@@ -154,7 +157,8 @@ Here is the fully stuffed *tree* tag that you can use in your templates: |
154 | 157 | (nodeMoved)="handleMoved($event)" |
155 | 158 | (nodeCreated)="handleCreated($event)" |
156 | 159 | (nodeExpanded)="handleExpanded($event)" |
157 | | - (nodeCollapsed)="handleCollapsed($event)"> |
| 160 | + (nodeCollapsed)="handleCollapsed($event)" |
| 161 | + (loadNextLevel)="handleNextLevel($event)"> |
158 | 162 | </tree> |
159 | 163 | ``` |
160 | 164 |
|
@@ -286,6 +290,27 @@ Another worth noting thing is `loadChildren`. This function on `TreeModel` allow |
286 | 290 | Node that defines this function is collapsed by default. At the moment of clicking 'Expand' arrow, it starts loading its children by calling given function. |
287 | 291 | If `loadChildren` function is given to the node - `children` property is ignored. For more details - have a look at the [Demo](#eyes-demo). |
288 | 292 |
|
| 293 | +#### Load children using ngrx (or any redux-like library) |
| 294 | + |
| 295 | +You can also load children by changing the tree state using ngrx. |
| 296 | +The tree can emit an appropriate event notifying you to dispatch a new action in order to load the branch's children. |
| 297 | + |
| 298 | +To enable this feature you should set the ```TreeModel.emitLoadNextLevel``` property to true: |
| 299 | + |
| 300 | + ```typscript |
| 301 | + const model: TreeModel = { |
| 302 | + emitLoadNextLevel : true |
| 303 | + } |
| 304 | + ``` |
| 305 | + |
| 306 | +Now on the first time the node is expanded a __LoadNextLevelEvent__ will be fired (via the __loadNextLevel__ EventEmitter in the tree) containing the node that requested a next level (its children) loading. |
| 307 | + |
| 308 | +In your code make sure you change the tree state and add the children to the model. |
| 309 | + |
| 310 | +In addition the regular __NodeExpanded__ event will be fired. |
| 311 | + |
| 312 | +__NOTICE__: if both ```emitLoadNextLevel``` and ```loadChildren``` are provided, the tree will ignore the ```emitLoadNextLevel``` and the ```LoadNextLevelEvent``` won't be fired. |
| 313 | + |
289 | 314 | #### Configure node via TreeModelSettings |
290 | 315 |
|
291 | 316 | Apart from that `TreeModel` interface has an optional field called `settings` of type `TreeModelSettings`. |
@@ -352,10 +377,6 @@ Also in the next section, you'll be reading about events generated by the `ng2-t |
352 | 377 |
|
353 | 378 | ### events (nodeMoved, nodeSelected, nodeRenamed, nodeRemoved, nodeCreated, nodeExpanded, nodeCollapsed) |
354 | 379 |
|
355 | | -Here is the diagram that shows tree events' hierarchy |
356 | | - |
357 | | - |
358 | | - |
359 | 380 | `NodeEvent` is the root of the tree events' hierarchy. It defines property `node` that contains a receiver of the event action (`node` is an instance of the `Tree` class). |
360 | 381 |
|
361 | 382 | `NodeDestructiveEvent` is the parent for all events that cause changes to the structure of the tree or to the node's value. |
@@ -490,6 +511,24 @@ You can subscribe to `NodeCollapsedEvent` by attaching listener to `(nodeCollaps |
490 | 511 | {node: <Tree>{...}} |
491 | 512 | ``` |
492 | 513 |
|
| 514 | +#### LoadNextLevelEvent |
| 515 | + |
| 516 | +You can subscribe to `LoadNextLevelEvent` by attaching a listener to `(loadNextLevel)` attribute. |
| 517 | +Relevant for loading children via ngrx (or any redux-inspired library). |
| 518 | + |
| 519 | +```html |
| 520 | + <tree |
| 521 | + [tree]="tree" |
| 522 | + (loadNextLevel)="handleNextLevel($event)"> |
| 523 | + </tree> |
| 524 | +``` |
| 525 | + |
| 526 | +`LoadNextLevelEvent` has a `node` property of the type `Tree`, which contains a node for which next level (its children) should be loaded. |
| 527 | + |
| 528 | +```typescript |
| 529 | +{node: <Tree>{...}} |
| 530 | +``` |
| 531 | + |
493 | 532 | ## :gun: Controller |
494 | 533 | First of all you should know how to get a controller of a particular node. You can get a controller of a node only if you set an id property of a node. For example, your tree structure should look like: |
495 | 534 |
|
@@ -625,6 +664,14 @@ oopNodeController.rename('new value'); |
625 | 664 |
|
626 | 665 | This method accepts a string and sets it as a node's new value, this action also fires rename event. |
627 | 666 |
|
| 667 | +#### startRenaming - changes the node template so that text input appears and lets a user type a new name |
| 668 | + |
| 669 | +```typescript |
| 670 | +oopNodeController.startRenaming(); |
| 671 | +``` |
| 672 | + |
| 673 | +After the user entered the new name a rename event will be fired. |
| 674 | + |
628 | 675 | #### remove - removes a node from the tree |
629 | 676 |
|
630 | 677 | ```typescript |
|
0 commit comments