Avalonia.Controls.TreeDataGrid icon indicating copy to clipboard operation
Avalonia.Controls.TreeDataGrid copied to clipboard

[Feature] Way of filtering items without losing data in Items container

Open MaxtorCoder opened this issue 2 years ago • 1 comments

Right now you have to remove the items when initializing either HierarchicalTreeDataGridSource or FlatTreeDataGridSource resulting in loss of data when, for example, selecting an entry from the TreeDataGrid.

My proposal is adding a Filter property when initializing either HierarchicalTreeDataGridSource or FlatTreeDataGridSource to filter out any item instances when a specific predicate is met.

Example:

class Node
{
    public string Name { get; set; }
    public bool IsDirectory { get; set; }
    public List<Node> Children { get; set; }
}

public HierarchicalTreeDataGridSource<Node> TreeDataGrid { get; set; }

...

public void PopulateDataGrid()
{
    // Fill Node Container...
    TreeDataGrid = new(<whatever_items>)
    {
        Columns =
        {
            new HierarchicalExpanderColumn<FileTreeNodeModel>(
                new TextColumn<FileTreeNodeModel, string>("Name", node => nide.Name),
                node => node.Cildren,
                node => node.Children.Count > 0),
        },
        Filter = node => node.IsDirectory
    };
}

This will only populate TreeDataGrid with the items that have IsDirectory set to true.

MaxtorCoder avatar Feb 23 '23 13:02 MaxtorCoder

Are similar functions supported?

AmberHan avatar May 24 '24 06:05 AmberHan