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
property icon DataSource IEnumerable Gets or sets the data source containing data for this control.
attribute
inner element
static value
bindable
default
null
property icon EmptyDataTemplate ITemplate Gets or sets the template which will be displayed when the data source is empty.
attribute
inner element
static value
bindable
default
null
property icon ItemChildrenBinding IValueBinding<IEnumerable<Object>> Gets or sets the binding which retrieves children of a data item.
attribute
inner element
static value
bindable
default
null
property icon ItemTagName String Gets or sets the name of the tag that wraps each hierarchy item (eg. li).
attribute
inner element
static value
bindable
default
null
property icon ItemTemplate ITemplate Gets or sets the template for each HierarchyRepeater item.
attribute
inner element
static value
bindable
default
null
property icon LevelTagName String Gets or sets the name of the tag that wraps each hierarchy level (eg. ul).
attribute
inner element
static value
bindable
default
null

HTML produced by the control