Tree findItem - how to exclude substrings?

I’ve coded the following: I create a node in a tree and it is given a default name eg NodeNew



Now if I create another node in a tree the code first looks to see if there already is a node with the default name using findItem(“NodeNew”);



Problem is if I rename the first created node to be “NodeNewFirst” then findItem(“NodeNew”) does not come back null ie it appears to search on substrings so how to exclude substrings?


findItem allows to search by substring.


Please, check the sample in your package: dhtmlxTree/samples/selection_sorting_navigation/pro_search.html


If the issue still appear, please provide the sample to support@dhtmlx.com to reproduce the issue.

Alex, I can see you are really busy and I think thats why you missed the point of my question
I know findItem  does a search by substring
I’m asking how to do a search that EXLUDES substrings.
I know findItem uses regex but I dont know how to use this to search on "whole word only"

Also is there a way of restricting the search to one parent?
Eg
parent1 -> NewNode

parent2-> NewNode1


I want to create parent2 -> NewNode
but only if parent2 does not have NewNode
I dont want a search to find parent1 -> NewNode
Thanks





Stephen,


sorry for being inattentive.


You can try to modify the search functionality directly in the dhtmlxtree.js:


try to locate line


searchStr = new RegExp(searchStr.replace(/([?*+\[]()]{1})/gi,"\$1").replace(/ /gi,"."),“gi”);


and replace it with


searchStr = new RegExp("^"+searchStr.replace(/([?*+\[]()]{1})/gi,"\$1").replace(/ /gi,".
")+"$",“gi”);

Alex that worked thank you very much.

I still need to restrict the search to below the selected node.
I understand the options are

tree
.findItem(searchString); //find item next to current selection
tree
.findItem(searchString,1,1); //find item previous to current selection
tree
.findItem(searchString,0,1); //find item from top

and I use the first one.

eg
parent1 -> NewNode

parent2-> NewNode1
parent2 is selected but findItem(NewNode) 
finds parent1 -> NewNode
how do I restrict the search to having selected parent2 as the top of the search tree?




Unfortunately, findItem doesn’t allow to do that.


You can try to create own search function.


There are following methods that can help in this case:


- getSubItems(itemId) (or getAllSubItems(itemId)) they allows to get a list of child items for a certain node


- getItemText(itemId).