HierarchyRepeater
in namespace DotVVM.BusinessPack.Controls
Repeats a template for each item in the hierarchical DataSource collection.
Usage & Scenarios
Repeats an item template at every level of a tree. Use it when you want to choose the markup for the hierarchy rather than display an interactive tree view.
Sample 1: Rendering nested folders
Bind DataSource to the root folders and ItemChildrenBinding to the children of each folder. ItemTemplate has the current folder as its data context at every depth. LevelTagName and ItemTagName turn the hierarchy into nested HTML lists.
Clear the list to see EmptyDataTemplate, then restore it to see the folders again.
<bp:HierarchyRepeater DataSource="{value: Folders}" ItemChildrenBinding="{value: Children}"
LevelTagName="ul" ItemTagName="li">
<ItemTemplate>{{value: Name}}</ItemTemplate>
<EmptyDataTemplate>No folders to display.</EmptyDataTemplate>
</bp:HierarchyRepeater>
<bp:Button Text="Clear folders" Click="{command: Clear()}" />
<bp:Button Text="Restore folders" Click="{command: Restore()}" />
using System.Collections.Generic;
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.HierarchyRepeater.sample1
{
public class ViewModel : DotvvmViewModelBase
{
public List<Folder> Folders { get; set; } = CreateFolders();
public void Clear() => Folders.Clear();
public void Restore() => Folders = CreateFolders();
private static List<Folder> CreateFolders() => new List<Folder>
{
new Folder { Name = "Projects", Children = { new Folder { Name = "Website" } } },
new Folder { Name = "Archive" }
};
}
public class Folder
{
public string Name { get; set; }
public List<Folder> Children { get; set; } = new List<Folder>();
}
}
Properties
| Name | Type | Description | Notes | Default Value | |
|---|---|---|---|---|---|
| ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
| DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
| DataSource | IEnumerable | Gets or sets the data source containing data for this control. |
attribute
bindable
|
null | |
| EmptyDataTemplate | ITemplate | Gets or sets the template which will be displayed when the data source is empty. |
inner element
static value
|
null | |
| ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
| IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
static value
bindable
|
True | |
| InnerText | String | Gets or sets the inner text of the HTML element. Note that this property can only be used on HtmlGenericControl directly and when the control does not have any children. |
attribute
static value
bindable
|
null | |
| ItemChildrenBinding | IValueBinding<IEnumerable<Object>> | Gets or sets the binding which retrieves children of a data item. |
attribute
bindable
|
null | |
| ItemTagName | String | Gets or sets the name of the tag that wraps each hierarchy item (eg. li). |
attribute
static value
|
null | |
| ItemTemplate | ITemplate | Gets or sets the template for each HierarchyRepeater item. |
inner element
static value
default
|
null | |
| LevelTagName | String | Gets or sets the name of the tag that wraps each hierarchy level (eg. ul). |
attribute
static value
|
null | |
| Visible | Boolean | Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control. |
attribute
static value
bindable
|
True |