Filter only on 3rd level of RadDropDownTree

1 Answer 39 Views
DropDownTree Filter
Clark
Top achievements
Rank 1
Iron
Iron
Clark asked on 13 Dec 2021, 09:10 PM | edited on 31 Mar 2022, 12:33 AM

Hello,

I would like to display the filter results of only the 3rd level nodes of my radDropDownTree.

In the example below, I only want 3rd level nodes that have "web"  in their text field displayed.

I've marked out what I don't want to see.

Thanks!

--Clark

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Peter Milchev
Telerik team
answered on 16 Dec 2021, 10:43 AM

Hi Clark,

This functionality would require overriding some of the internal filtering functions of the DropDownTree. To do that, you can please the following script somewhere below the ScriptManager:

<script>
    var $T = Telerik.Web.UI;
    Telerik.Web.UI.RadDropDownTree.Manager.prototype._filterNodes = function (text) {
        var nodes = this._embeddedTree.get_allNodes(),
            count = nodes.length,
            regEx,
            i;

        if (this._filter == $T.DropDownTreeFilter.StartsWith)
            regEx = new RegExp("^\\s*" + $T.RadDropDownTree.Manager._regExEscape(text), "im");
        else
            regEx = new RegExp($T.RadDropDownTree.Manager._regExEscape(text), "gim");

        for (i = 0; i < count; i++) {
            var currentNode = nodes[i];
            var matchIsFound;
                   
            if (currentNode.get_level() !== 2) {
                matchIsFound = false;
            } else {
                matchIsFound = this._matchNode(currentNode, text, regEx);
            }
            if (matchIsFound) {
                this._handleVisibleParents(currentNode);
                this._filteredVisibleNodes.push(currentNode);
            }
            else {
                this._handleHiddenNode(currentNode);
            }
        }

        this._hideNodes(this._filteredHiddenNodes);
        this._showNodes(this._filteredVisibleNodes);

        this._filteredVisibleNodes = [];
        this._filteredHiddenNodes = [];
    }
</script>

Regards,
Peter Milchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Clark
Top achievements
Rank 1
Iron
Iron
commented on 16 Dec 2021, 05:01 PM | edited

Hello Peter,

This worked perfectly  😀

It's also a good resource for how filtering works and how to modify it.

Thanks and good job!

--Clark

 

 

Tags
DropDownTree Filter
Asked by
Clark
Top achievements
Rank 1
Iron
Iron
Answers by
Peter Milchev
Telerik team
Share this question
or