Filtering in UWP TreeGrid (SfTreeGrid)

Overview

SfTreeGrid provides support for programmatic filtering. It can be achieved by setting SfTreeGrid.View.Filter delegate and calling SfTreeGrid.View.RefreshFilter method.

public bool FilerNodes(object o)
{
    var data = o as Employee;

    if (data.Salary > 70000)
        return true;
    return false;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    treeGrid.View.Filter = FilerNodes;
    treeGrid.View.RefreshFilter();
}

Here, FilterNodes delegate filters the data based on Salary. FilterNodes delegate is assigned to SfTreeGrid.View.Filter predicate to filter the tree grid. After that, SfTreeGrid.View.RefreshFilter method is called to refresh the nodes. If the node satisfies the filter conditions, true will be returned. Else false will be returned.
Filtering_img1

While filtering, if the node satisfies filter condition, IsFiltered property of TreeNode will be set as false. Else, it will be true. If IsFiltered value is True, the node will not be displayed in view, else it will be displayed in view.

NOTE

SfTreeGrid refreshes the filtering on property change if SfTreeGrid.LiveNodeUpdateMode property is set as AllowDataShaping.

You can download the sample from here.

FilterLevel

You can filter the nodes based on level by using SfTreeGrid.FilterLevel property.

treeGrid.FilterLevel = FilterLevel.All;
  • Root - Filter will be applied to root nodes only in SfTreeGrid.

  • All - Filter will be applied to all the nodes in SfTreeGrid.

  • Extended - Filter will be applied to all the nodes. If a node matches the filter condition, it’s all ancestors will also be displayed, even though parent node does not match the filter condition.

Root

Filter will be applied to root nodes only in SfTreeGrid. For other nodes, IsFiltered value will be false and they always will be displayed in view.

All

Filter will be applied to all the nodes in SfTreeGrid. If the parent node does not match the filter condition, filter will not be applied for child nodes. Else, filter will be applied to its child nodes also.

Extended

Filter will be applied to all the nodes. If a node matches the filter condition, it’s all ancestors will also be displayed, even though parent node does not match the filter condition and parent node’s IsFiltered value will be set as false.

NOTE

It is also possible to change FilterLevel at runtime.

Clear filters

You can clear the filters applied in tree grid by setting SfTreeGrid.View.Filter delegate as null and calling SfTreeGrid.View.RefreshFilter method.

treeGrid.View.Filter = null;
treeGrid.View.RefreshFilter();

HasVisibleChildNodes

You can find whether particular node has child node(s) displayed in a view (matches filtering criteria) or not by using HasVisibleChildNodes property in TreeNode.

var treeNode=treeGrid.View.Nodes[0];
var hasVisibleChildNodes = treeNode.HasVisibleChildNodes;