BzTreeView

Tree view

Multi-select, icons and per-node action buttons.

Multi-select + actions

The tree works with any model: just tell it where to read each node's text, children and icon from.

فروش
انبار
تنظیمات
Member Description
ItemsThe root nodes
TextSelectorWhere each node's label comes from
ChildrenSelectorWhere each node's children come from
IconSelectorEach node's icon (optional)
MultiSelectCheckbox multi-selection
NodeActionsPer-node buttons; the node itself is in context
ExpandAll() / CollapseAll()Called through a ref
GetSelected()The list of selected nodes
razor
@using BzCore.Components.Tree
@using BzCore.Components.Button
@using BzCore.Enums

<BzTreeView @ref="_tree" TItem="TreeNode" Items="_roots"
            TextSelector="@(n => n.Name)"
            ChildrenSelector="@(n => n.Children)"
            IconSelector="@(n => n.Icon)"
            MultiSelect="true">
    <NodeActions>
        @* context is the node this row renders *@
        <BzButton Size="BzSize.Small" Variant="BzButtonVariant.Text" IconOnly
                  StartIcon="fa-solid fa-pen"
                  OnClick="@(() => _msg = $"ویرایش: {context.Name}")" />
        <BzButton Size="BzSize.Small" Variant="BzButtonVariant.Text" IconOnly
                  StartIcon="fa-solid fa-trash" Color="BzColor.Danger"
                  OnClick="@(() => _msg = $"حذف: {context.Name}")" />
    </NodeActions>
</BzTreeView>

<BzButton Size="BzSize.Small" Text="باز کردن همه" Variant="BzButtonVariant.Soft"
          OnClick="@(() => _tree.ExpandAll())" />
<BzButton Size="BzSize.Small" Text="بستن همه" Variant="BzButtonVariant.Soft"
          OnClick="@(() => _tree.CollapseAll())" />
<BzButton Size="BzSize.Small" Text="انتخاب شده ها" OnClick="ShowSelected" />

@if (!string.IsNullOrEmpty(_msg)) { <p>@_msg</p> }

@code {
    private BzTreeView<TreeNode> _tree = default!;
    private string? _msg;

    // Your own model — the tree only needs the three selectors above.
    public class TreeNode
    {
        public string Name { get; set; } = "";
        public string? Icon { get; set; }
        public List<TreeNode> Children { get; set; } = new();
    }

    private List<TreeNode> _roots = new()
    {
        new TreeNode { Name = "فروش", Icon = "fa-solid fa-cart-shopping", Children =
        {
            new TreeNode { Name = "سفارش ها", Icon = "fa-solid fa-receipt" },
            new TreeNode { Name = "مشتری ها", Icon = "fa-solid fa-users", Children =
            {
                new TreeNode { Name = "حقیقی", Icon = "fa-solid fa-user" },
                new TreeNode { Name = "حقوقی", Icon = "fa-solid fa-building" },
            }},
        }},
        new TreeNode { Name = "انبار", Icon = "fa-solid fa-warehouse" },
    };

    private void ShowSelected()
    {
        var names = _tree.GetSelected().Select(n => n.Name);
        _msg = "انتخاب شده: " + string.Join("، ", names);
    }
}