You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -4,10 +4,6 @@ description: A guide to creating a custom tree in Umbraco
4
4
5
5
# Trees
6
6
7
-
{% hint style="warning" %}
8
-
This page is a work in progress and may undergo further revisions, updates, or amendments. The information contained herein is subject to change without notice.
9
-
{% endhint %}
10
-
11
7
The tree is a hierarchical structure of nodes and is registered in the Backoffice extension registry. A tree can be rendered anywhere in the Backoffice with the help of the `<umb-tree />` element.
12
8
13
9
{% hint style="info" %}
@@ -16,13 +12,11 @@ If you are looking for information on how to register a tree as a menu in a sect
16
12
17
13
## Creating trees <ahref="#creating-trees"id="creating-trees"></a>
18
14
19
-
To Create a Tree in a section of the Umbraco backoffice, you need to take multiple steps:
15
+
To create a Tree in the Backoffice, you need to take multiple steps:
20
16
21
17
### Registering a tree <ahref="#registering-a-tree"id="registering-a-tree"></a>
22
18
23
-
The backoffice comes with two different tree item kinds out of the box: entity and fileSystem.
24
-
25
-
Tree Manifest:
19
+
To register a tree, you need to create a manifest:
26
20
27
21
```json
28
22
{
@@ -32,15 +26,6 @@ Tree Manifest:
32
26
"meta": {
33
27
"repositoryAlias": "My.Repository.Alias"
34
28
}
35
-
},
36
-
{
37
-
"type": "treeItem",
38
-
"kind": "entity",
39
-
"alias": "My.TreeItem.Alias",
40
-
"name": "My Tree Item",
41
-
"conditions": {
42
-
"entityType": "my-entity-type",
43
-
},
44
29
}
45
30
```
46
31
@@ -54,7 +39,7 @@ To render a tree in the Backoffice, you can use the `<umb-tree>` element. You ne
54
39
55
40
### Render a Custom Tree Item <ahref="#render-a-custom-tree-item"id="render-a-custom-tree-item"></a>
56
41
57
-
The `<umb-tree />` element will render the tree items based on the registered tree item alias. If you want to render a custom tree item, you need to register a tree item manifest. This manifest can then show a custom element for the tree item.
42
+
The `<umb-tree />` element will render the tree items based on the registered tree item alias. The tree will be rendered using the [<umb-default-tree-item />](https://apidocs.umbraco.com/v16/ui-api/classes/packages_core_tree.UmbDefaultTreeItemElement.html) element by default. If you want to render a custom tree item, you need to register a tree item manifest. This manifest can then show a custom element for the tree item.
58
43
59
44
#### **The Tree Item Manifest**
60
45
@@ -72,88 +57,144 @@ The `<umb-tree />` element will render the tree items based on the registered tr
72
57
73
58
#### The Tree Item Element <ahref="#the-tree-item-element"id="the-tree-item-element"></a>
74
59
75
-
To create a custom tree item, you need to create a custom element. This element can choose to use the `<umb-tree-item-base>` element underneath. However, it can also be used as a standalone element if you prefer to implement the tree item logic yourself.
60
+
To create a custom tree item, you need to create a custom element. This element can optionally extend the [UmbTreeItemElementBase<T>](https://apidocs.umbraco.com/v16/ui-api/classes/packages_core_tree.UmbTreeItemElementBase.html) class. However, it can also be used as a standalone element if you prefer to implement the tree item logic yourself.
76
61
77
-
In this example, we will create a custom tree item that uses the `<umb-tree-item-base>` element. This base element provides the necessary context and functionality for the tree item.
62
+
In this example, we will create a custom tree item that extends the base class. The base class provides the necessary context and functionality for the tree item.
#### The Tree Item Context <ahref="#the-tree-item-context"id="the-tree-item-context"></a>
110
-
111
-
The tree item context is a class that provides the necessary functionality for the tree item. It is used to manage the state of the tree item, such as loading children, selecting, and deselecting the item.
85
+
#### The Tree Item Model <ahref="#extending-the-tree-item-model"id="extending-the-tree-item-model"></a>
112
86
113
-
You can create a custom tree item context by implementing the `UmbTreeItemContext<T>` interface.
87
+
To define the data model for your tree item, you can create a model that extends the [UmbTreeItemModel](https://apidocs.umbraco.com/v16/ui-api/interfaces/packages_core_tree.UmbTreeItemModel.html). This model will be used to provide the data for your custom tree item.
// Add any additional properties you need for your tree item
142
95
}
143
96
```
97
+
{% endcode %}
98
+
144
99
145
-
#### Extending the Tree Item Context base <ahref="#extending-the-tree-item-context-base"id="extending-the-tree-item-context-base"></a>
100
+
###Adding data to the tree <ahref="#adding-data-to-the-tree"id="adding-data-to-the-tree"></a>
146
101
147
-
The easiest way to create a custom tree item context is to extend the `UmbTreeItemContextBase<T>` class. This class provides a lot of the functionality you need out of the box, such as loading children, selecting, and deselecting the item.
102
+
To add data to the tree, you need to create a repository that will provide the data for the tree. The repository is defined in the manifest of the tree and linked through its `repositoryAlias`.
148
103
149
-
We provide a base class for the tree item context. This class provides some default implementations for the context. You can extend this class to overwrite any of the default implementations.
104
+
```json
105
+
{
106
+
"type": "repository",
107
+
"alias": "My.Repository.Alias",
108
+
"name": "My Repository",
109
+
"api": "./my-repository.js"
110
+
}
111
+
```
150
112
113
+
#### Implementing the repository <ahref="#implementing-the-repository"id="implementing-the-repository"></a>
114
+
115
+
The repository needs to be able to fetch data for the tree. You can implement the repository as a class that extends the [UmbTreeRepositoryBase](https://apidocs.umbraco.com/v16/ui-api/classes/packages_core_tree.UmbTreeRepositoryBase.html) class. This class provides the necessary methods to fetch data for the tree.
#### Implementing the data source <ahref="#implementing-the-data-source"id="implementing-the-data-source"></a>
132
+
133
+
The data source is responsible for fetching the data for the tree. You can implement the data source as a class that implements the [UmbTreeDataSource](https://apidocs.umbraco.com/v16/ui-api/interfaces/packages_core_tree.UmbTreeDataSource.html) interface.
## Further reading <ahref="#further-reading"id="further-reading"></a>
199
+
200
+
For more information on trees, you can refer to the examples folder in the GitHub repository: [Umbraco UI Examples - Trees](https://github.com/umbraco/Umbraco-CMS/tree/main/src/Umbraco.Web.UI.Client/examples/tree)
0 commit comments