Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Large trees

Since 0.1.0-alpha.21
Children that load when a branch first opens, and a search box that narrows the tree.

Children that load

For a tree too large to send at once, set ItemHasChildren and ChildrenProvider. The first time a branch opens, the provider gets the item's key and returns its children.

Static

Preview

  • Projects
    Loading Turn on JavaScript to see these items. Couldn't load the items.
  • Archive
    Loading Turn on JavaScript to see these items. Couldn't load the items.
  • notes.txt

Code

LoadChildren.razor
@* Each folder's contents load the first time it opens. On a static page the script asks the page
   for them with the folder's key; on an interactive page the component calls ChildrenProvider. *@
<TreeView Items="Roots" ItemKey="f => f.Path" ItemText="f => f.Name" ItemIcon="@(f => f.Folder ? Lucide.Folder : Lucide.File)"
          ItemHasChildren="f => f.Folder" ChildrenProvider="LoadAsync" MaxWidth="20.Rem" Grow />

@code {
    private static readonly Entry[] Roots = [new("projects", "Projects", true), new("archive", "Archive", true), new("notes.txt", "notes.txt", false)];

    private static async ValueTask<IEnumerable<Entry>> LoadAsync(string path, CancellationToken cancellationToken)
    {
        await Task.Delay(400, cancellationToken); // A slow store, for the demo.
        var depth = path.Count(c => c == '/');
        Entry[] folders = depth < 2 ? [new($"{path}/2025", "2025", true), new($"{path}/2026", "2026", true)] : [];
        return [.. folders, new($"{path}/readme.md", "readme.md", false), new($"{path}/plan.txt", "plan.txt", false)];
    }
}

On static pages, IzzyBlazor's script asks the page for the children, so there's no endpoint to write. Give each tree on the page that loads children an id.

With JavaScript off, those branches say to turn it on.

To add a search box, set Searchable. Typing narrows the tree to the matches and the branches that hold them, and marks the matched text. It searches the items in the page, so children still to load aren't found.

Connection lost

Rejoining the server…