Please help me or give an idea to do search/filter from tree data in perspective
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.
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
With tags? Or other arbitrary data?
{ Samples, please. }
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...
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.
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:
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)
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....
sry to tag you here but need help ..plz check if you can help me on this @victordcq
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
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 (7.6 KB)
Ok sure, Thank u so much