# Search/Filter on tree data

**URL:** <https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [July 18, 2023, 12:19pm UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513 "2023-07-18T12:19:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![manjuyadav95.m](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@manjuyadav95.m](https://forum.inductiveautomation.com/u/manjuyadav95.m)\
**Post date:** [July 18, 2023, 12:19pm UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/1 "2023-07-18T12:19:40Z")

</div>

Please help me or give an idea to do search/filter from tree data in perspective

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 18, 2023, 12:23pm UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/2 "2023-07-18T12:23:01Z")

</div>

Please expand your question to include:

- A sample of the data you currently have (with private stuff cut out),

- A sample of the filtered data you wish to achieve,

- The code you've already tried, and the results it produced.

---

<div class="post-metadata">

**Author:** ![manjuyadav95.m](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@manjuyadav95.m](https://forum.inductiveautomation.com/u/manjuyadav95.m)\
**Post date:** [July 18, 2023, 12:30pm UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/3 "2023-07-18T12:30:42Z")

</div>

Thanks for your reply. I have shared the link below thats what i want but in this it's searched by tag path but i wanna achieve it by typing any keys into the search field

> [@Perspective Progressive Tag Tree](https://forum.inductiveautomation.com/t/perspective-progressive-tag-tree/35495/15):
>
> Progress Update: Creating a filtered list = Easy Creating the list of all the filtered tag indices within the tree = Easy Expanding the list automatically = Easy to do, but very slow… I have it currently working in a format that expands all of the tags that match your search and highlights them. It works ok with my example (about 1000 tags) but still isnt as fast as I would like. Top items to correct: It needs to also remove/hide the tags and paths that don’t match the filter. In my exampl…

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 18, 2023, 1:06pm UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/4 "2023-07-18T13:06:58Z")

</div>

> [@manjuyadav95.m](#):
>
> but i wanna achieve it by typing any keys into the search field

With tags? Or other arbitrary data?

{ Samples, please. }

---

<div class="post-metadata">

**Author:** ![manjuyadav95.m](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@manjuyadav95.m](https://forum.inductiveautomation.com/u/manjuyadav95.m)\
**Post date:** [July 18, 2023, 6:22pm UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/5 "2023-07-18T18:22:04Z")

</div>

Please see below image for the data example ...nodes should get filtered by entered text ...for example if I enter abc-1 then its parent node(under which abc-1 node is present) n the exact node(abc) and its child node should be displayed and when I remove the text then previous data should get populated on tree data...

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/b/4b9a3a1e9ec091793c01807badc379c1d03cfe93.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 18, 2023, 7:25pm UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/6 "2023-07-18T19:25:45Z")

</div>

Tip: Please use full words, sentences, capitals and proper punctuation etc., so we can understand your writing and to help anyone using machine translation into another language. Make it easy for your readers you are asking to give of their time to help you.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 18, 2023, 7:30pm UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/7 "2023-07-18T19:30:33Z")

</div>

A recursive script would likely be needed. If you have the source data in a flat format, then the technique in this post might help, by filtering (with `where()`) then generating the tree:

> [@Automation Professionals' Integration Toolkit Module](https://forum.inductiveautomation.com/t/automation-professionals-simulation-aids-v2/74934/13):
>
> No longer true. grin For Ignition v8.1+: v2.0.3.231942018 With @Matthew.gaitan 's input dataset in a custom property named source, this expression: forEach( asMap( groupBy( {this.custom.source}, it()['RouteName'], it()['StopName'] ) ), asMap( 'label', it()[0], 'expanded', false, 'data', asMap('nodeType', 'Route'), 'items', forEach( it()[1], asMap( 'label', it()[0], 'expanded', false, 'data', asMap('nodeType', 'Stop'), 'items', forEach( it(…

---

<div class="post-metadata">

**Author:** ![manjuyadav95.m](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@manjuyadav95.m](https://forum.inductiveautomation.com/u/manjuyadav95.m)\
**Post date:** [July 19, 2023, 6:25am UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/8 "2023-07-19T06:25:04Z")

</div>

sorry, I gone through this thread but I am not getting ...please help me with below code , I am checking that filter text n any of the label from tree data is matching or not. if matched then that particular complete node/item(including child) should be copied or else other items should be removed  
refer from above shared example data: if i enter abc then abc complete node should be copied or else other items that is def node should be removed/deleted and if i unfilter then back to all data (abc n def both nodes should be displayed)

```auto
vTreeData=self.parent.getChild("cntrfilter").getChild("treeFilter").props.items
vFilterText=self.parent.getChild("cntrfilter").getChild("txtSearch").props.text
	
for i in range(len(vTreeData)):
	vId=self.parent.getChild("cntrfilter").getChild("treeFilter").props.items[i].label
	if vFilterText==vId:
		vFilteredData=self.parent.getChild("cntrfilter").getChild("treeFilter").props.items[i]
		import json
		vFilteredData = json.loads(vFilteredData)
		self.parent.getChild("cntrfilter").getChild("treeFilter").props.items=vFilteredData

```

i want the same way as how Ignition designer project browser search works....  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/4/64043050d23ed5f4fb336ba948f45173d8f7ea46.png)

sry to tag you here but need help ..plz check if you can help me on this @victordcq

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [July 20, 2023, 11:57am UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/9 "2023-07-20T11:57:18Z")

</div>

a basic resursive filter should be a kinda basic skill for a python programmer...  
even with lowercase or regex support  
i suggest you look up how it works, instead of just copying my workxd

```auto
	import re
	
	if not len(value.filter):
		return value.items
		
	def recursiveSearch(items, key):
		returnList = []		
		for item in items:
			if bool(re.search(key,item.label.lower())):				
				returnList.append(item)
			elif len(item.items):
				returnList += (recursiveSearch(item.items, key))
		if (returnList):
			return returnList
		return []
	
	return recursiveSearch(value.items, value.filter.lower())

```

[filtertree.zip](https://forum.inductiveautomation.com/uploads/short-url/foF4k6lWpAkXjzVvbBrg9V6pHsy.zip) (7.6 KB)

---

<div class="post-metadata">

**Author:** ![manjuyadav95.m](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@manjuyadav95.m](https://forum.inductiveautomation.com/u/manjuyadav95.m)\
**Post date:** [July 20, 2023, 1:50pm UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/10 "2023-07-20T13:50:33Z")

</div>

Ok sure, Thank u so much

---

<div class="post-metadata">

**Author:** ![MESConsultant](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@MESConsultant](https://forum.inductiveautomation.com/u/MESConsultant)\
**Post date:** [April 6, 2025, 8:18am UTC](https://forum.inductiveautomation.com/t/search-filter-on-tree-data/76513/11 "2025-04-06T08:18:08Z")

</div>

Hello,

I designed a structure where search can be performed in a tree table. I’m not sure if it’s worth sharing on the Exchange. Maybe it’s too simple 🙂
