Skip to content

Commit 9321d22

Browse files
docs(treeview): clarify behavior
1 parent c20d665 commit 9321d22

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

_contentTemplates/treeview/basic-example.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818
public bool HasChildren { get; set; }
1919
public string Icon { get; set; }
2020
public bool Expanded { get; set; }
21-
22-
public TreeItem()
23-
{
24-
}
2521
}
22+
2623
public IEnumerable<TreeItem> FlatData { get; set; }
2724
2825
protected override void OnInit()

components/treeview/data-binding/flat-data.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Flat data means that the entire collection of treeview items is available at one
1818

1919
The parent-child relationships are created through internal data in the model - the `ParentId` field which points to the `Id` of the item that will contain the current item. The root level has `null` for `ParentId`.
2020

21+
You must also provide the correct value for the `HasChildren` field - for items that have children, you must set it to `true` so that the expand arrow is rendered.
22+
2123
>caption Example of flat data in a treeview
2224
2325
````CSHTML

components/treeview/data-binding/hierarchical-data.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ This article explains how to bind the TreeView for Blazor to hierarchical data.
1414
@[template](/_contentTemplates/treeview/basic-example.md#data-binding-basics-link)
1515

1616

17-
Hierarchical data means that the collection child items is provided in a field of its parent's model. By default, this is the `Items` field.
17+
Hierarchical data means that the collection child items is provided in a field of its parent's model. By default, this is the `Items` field. If there are items for a certain node, it will have an expand icon. The `HasChildren` field can override this, however, but it is not required for hierarchical data binding.
1818

19-
This lets you gather separate collections of data and/or use different models at each different level. Note that the data binding settings are per level, so a certain level will always use the same bindings, regardless of the model they represent and their parent.
19+
This approach of providing nodes lets you gather separate collections of data and/or use different models at each different level. Note that the data binding settings are per level, so a certain level will always use the same bindings, regardless of the model they represent and their parent.
2020

2121
>caption Example of hierarchical data that uses different models for the parent and the child. Using different models is not required.
2222
@@ -38,7 +38,6 @@ This lets you gather separate collections of data and/or use different models at
3838
public string Category { get; set; }
3939
public List<ProductItem> Products { get; set; }
4040
public bool Expanded { get; set; }
41-
public bool HasChildren { get; set; }
4241
}
4342
4443
public class ProductItem
@@ -48,7 +47,6 @@ This lets you gather separate collections of data and/or use different models at
4847
// they are not really used in this example and you would have a collection of child items too
4948
// see the information about multiple data bindings earlier in this article on using them
5049
public bool Expanded { get; set; }
51-
public bool HasChildren { get; set; }
5250
}
5351
5452
@@ -71,8 +69,7 @@ This lets you gather separate collections of data and/or use different models at
7169
{
7270
Category = "Category 1",
7371
Expanded = true,
74-
Products = firstCategoryProducts, // this is how child items are provided
75-
HasChildren = firstCategoryProducts?.Count > 0, // set this depending on the presence of items in the child items collection
72+
Products = firstCategoryProducts // this is how child items are provided
7673
7774
});
7875

components/treeview/data-binding/overview.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ There are three modes of providing data to a treeview, and they all use the item
2727

2828
The treeview items provide the following features that you control through the corresponding fields in their data binding:
2929

30-
* `Id` - a unique identifier for the item. Required.
31-
* `ParentId` - identifies the parent to whom the item belongs. Needed only when binding to flat data. All items with the same `ParentId` will be rendered at the same level. For a root level item, this must be `null`.
30+
* `Id` - a unique identifier for the item. Required for binding to flat data.
31+
* `ParentId` - identifies the parent to whom the item belongs. Required only when binding to flat data. All items with the same `ParentId` will be rendered at the same level. For a root level item, this must be `null`.
32+
* `Expanded` - whether the item is expanded when it renders, or the user has to expand it manually.
33+
* `HasChildren` - whether the item has children. Determines whether an expand arrow is rendered next to the item. Required for binding to flat data and for load-on-demand. With hierarchical data, the treeview will render the icon based on the existence of child items, but `HasChildren` will take precedence.
34+
* `Items` - the collection of child items that will be rendered under the current item. Required only when binding to hierarchical data.
3235
* `Text` - the text that will be shown on the item.
3336
* `Icon` / `IconClass` / `ImageUrl` - the [Telerik icon]({%slug general-information/font-icons%}), a class for a custom font icon, or the URL to a raster image that will be rendered in the item. They have the listed order of precedence in case more than one is present in the data (that is, an `Icon` will have the highest importance).
34-
* `Expanded` - whether the item is expanded when it renders, or the user has to expand it manually.
35-
* `HasChildren` - whether the item has children. Determines whether an expand arrow is rendered next to the item. Required.
36-
* `Items` - the collection of child items that will be rendered under the current item. Needed only when binding to hierarchical data.
3737

3838
## Data Bindings
3939

0 commit comments

Comments
 (0)