Tree searching/finding


We use the registered version of dhtmlx.

I’m using a findItem command to search for an item in the Tree.
But now we want to search within a custom Attribute.
This way, we can find unique codes easily.

So in the XML we would have:

We would like to have the same behaviour as the findItem command.

Could this be implemented into dhtmlx tree?
Or is there an easier way to do this myself?



You need to iterate all the items and get this attribute:
attr = tree.getAttribute(itemId, attribute);
Than you need to focus this item:

Ah yes. But unfortunately the “unique”-code occurs more than once.

findItem find the next entity. Where the iteration would start over again.
So, the findItem is more advanced :slight_smile:
I would have to write a similar function like findItem and that takes too much time.

Other solutions?

Can you provide us a piece of your xml with the repeating attributes?

Sure, I hope it is clear.

If I would use the text-attribute and use findItem(‘Seagate’,0,0) it would find al the other Item Id’s aswell.

That’s why I would like to sure another attribute. And itterate through them.
But with the posibility to search from the current position :slight_smile:

<tree id="0" > <item id="4456" groepcode="harddisk" text="g1: Harddisk products"> <item id="4352" groepcode="CMS_HDSATA25" text="g2: Laptop SATA"> <item id="813" groepcode="HD_TOSSATA" text="g3: Toshiba Notebook Harddisk SATA" /> <item id="837" groepcode="HD_WD_SBL" text="g3: Western Digital Scorpio Blue SATA Laptop Harddisk" /> <item id="787" groepcode="HD_SEEES" text="g3: Seagate EE25 Notebook Harddisk SATA" /> <item id="796" groepcode="HD_SEMOS" text="g3: Seagate Momentus Notebook Harddisk SATA" /> <item id="779" groepcode="HD_SECOSA" text="g3: Seagate Constellation Notebook Harddisk SATA" /> <item id="834" groepcode="HD_WD_SATA25" text="g3: Western Digital Notebook Harddisk SATA" /> <item id="774" groepcode="HD_SEA_SATA25" text="g3: Seagate Notebook Harddisk SATA" /> <item id="753" groepcode="HD_MAX_SATA25" text="g3: Maxtor Notebook Harddisk SATA" /> <item id="746" groepcode="HD_FUJ_SATA25" text="g3: Fujitsu Notebook Harddisk SATA" /> <item id="1073" groepcode="SAMSTOHDDFF2" text="g3: Samsung Laptop (2.5") SATA PATA" /> </item> <item id="4351" groepcode="CMS_SEAGATE" tooltip="844" text="g2: Seagate"> <item id="987" groepcode="HD_SEEES" tooltip="653" text="g3: Seagate EE25 Notebook Harddisk SATA" /> <item id="996" groepcode="HD_SEMOS" tooltip="652" text="g3: Seagate Momentus Notebook Harddisk SATA" /> <item id="979" groepcode="HD_SECOSA" tooltip="648" text="g3: Seagate Constellation Notebook Harddisk SATA" /> <item id="974" groepcode="HD_SEA_SATA25" tooltip="595" text="g3: Seagate Notebook Harddisk SATA" /> </item> </item> </tree>



There is no ready approach, but i can shoe you, how to iterate all the items you neeed:

function find1(){ var all = dhxTree.getAllSubItems(0); var splited = all.split(','); var id; for (var i=0; i<splitted.length; i++){ id = splitted[i]; //put your search algorithm here } }
Recommend you to consider some of the next methods:

ok, thank you.

But the tricky thing is to find from the current position.
And findItem does right that. :slight_smile:

But I’ll try to create something myself.
Thanks you for help.

You are welcome!