<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Searching elements in Tree box in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/867118#M102988</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Is it feasible to search for elements in a tree box?&lt;BR /&gt;The method shown in the link below searches for user-entered elements in a list box, but this approach does not apply to a tree box. &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/td-p/380361" target="_self"&gt;Searching elements in listbox&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is because a list box can easily use a loop to search through all items. What methods can be used to search for elements in a tree box?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV data-container=""&gt;&lt;SPAN class="ThemeGrid_MarginGutter" data-expression=""&gt;The following JSL is an example of creating a simple tree box.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV data-container=""&gt;
&lt;DIV id="l3-6_3-ConGood" class="OSInline" data-container=""&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt=New Table( "Food Tree",
	Add Rows( 8 ),
	New Column( "Name",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"Apple", "Banana", "Watermelon", "Fruit", "Broccoli", "Lettuce",
			"Potato", "Vegetable"}
		)
	),
	New Column( "Category",
		Character,
		"Nominal",
		Set Values(
			{"Fruit", "Fruit", "Fruit", "", "Vegetable", "Vegetable", "Vegetable",
			""}
		)
	),
	New Column( "Level",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [2, 2, 2, 1, 2, 2, 2, 1] )
	),
	Set Row States( [0, 0, 0, 1, 0, 0, 0, 0] )
);
relations = [=&amp;gt;];
For Each Row( dt,
	relations[:Name] = Tree Node( :Name );
	relations[:Name] &amp;lt;&amp;lt;Set Data( Eval List( {:Name, :Category,  :Level} ) );
);
roots = {};
For Each Row( dt,
	If( :Category != "" &amp;amp; relations &amp;lt;&amp;lt; Contains( :Category ),
		relations[:Category] &amp;lt;&amp;lt; Append( relations[:Name] )
	,
		roots[N Items( roots ) + 1] = relations[:Name]
	);
);
New Window( "TreeBox Tests", 
	tree = Tree Box( roots, Size( 300, 500 ) ) );

key = relations &amp;lt;&amp;lt; First;
While( !Is Empty( key ),
	Try( tree &amp;lt;&amp;lt; Expand( relations[key] ) );
	key = relations &amp;lt;&amp;lt; Next( key )
);
tree &amp;lt;&amp;lt; Set Node Select Script(
	Function( {this, node},
		Print( node &amp;lt;&amp;lt; Get Data )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Apr 2025 11:47:47 GMT</pubDate>
    <dc:creator>BabyDoragon</dc:creator>
    <dc:date>2025-04-09T11:47:47Z</dc:date>
    <item>
      <title>Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/867118#M102988</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Is it feasible to search for elements in a tree box?&lt;BR /&gt;The method shown in the link below searches for user-entered elements in a list box, but this approach does not apply to a tree box. &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/td-p/380361" target="_self"&gt;Searching elements in listbox&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is because a list box can easily use a loop to search through all items. What methods can be used to search for elements in a tree box?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV data-container=""&gt;&lt;SPAN class="ThemeGrid_MarginGutter" data-expression=""&gt;The following JSL is an example of creating a simple tree box.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV data-container=""&gt;
&lt;DIV id="l3-6_3-ConGood" class="OSInline" data-container=""&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt=New Table( "Food Tree",
	Add Rows( 8 ),
	New Column( "Name",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"Apple", "Banana", "Watermelon", "Fruit", "Broccoli", "Lettuce",
			"Potato", "Vegetable"}
		)
	),
	New Column( "Category",
		Character,
		"Nominal",
		Set Values(
			{"Fruit", "Fruit", "Fruit", "", "Vegetable", "Vegetable", "Vegetable",
			""}
		)
	),
	New Column( "Level",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [2, 2, 2, 1, 2, 2, 2, 1] )
	),
	Set Row States( [0, 0, 0, 1, 0, 0, 0, 0] )
);
relations = [=&amp;gt;];
For Each Row( dt,
	relations[:Name] = Tree Node( :Name );
	relations[:Name] &amp;lt;&amp;lt;Set Data( Eval List( {:Name, :Category,  :Level} ) );
);
roots = {};
For Each Row( dt,
	If( :Category != "" &amp;amp; relations &amp;lt;&amp;lt; Contains( :Category ),
		relations[:Category] &amp;lt;&amp;lt; Append( relations[:Name] )
	,
		roots[N Items( roots ) + 1] = relations[:Name]
	);
);
New Window( "TreeBox Tests", 
	tree = Tree Box( roots, Size( 300, 500 ) ) );

key = relations &amp;lt;&amp;lt; First;
While( !Is Empty( key ),
	Try( tree &amp;lt;&amp;lt; Expand( relations[key] ) );
	key = relations &amp;lt;&amp;lt; Next( key )
);
tree &amp;lt;&amp;lt; Set Node Select Script(
	Function( {this, node},
		Print( node &amp;lt;&amp;lt; Get Data )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:47:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/867118#M102988</guid>
      <dc:creator>BabyDoragon</dc:creator>
      <dc:date>2025-04-09T11:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/867932#M103076</link>
      <description>&lt;P&gt;It is feasible, how do wish to search for them? What you wish to do after they are found?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example take a look &lt;STRONG&gt;old script&lt;/STRONG&gt; I mentioned here &lt;A href="https://community.jmp.com/t5/Uncharted/Directory-Tree-Explore-Space-Used-by-Folders/bc-p/456618/highlight/true#M329" target="_blank" rel="noopener"&gt; Directory Tree: Explore Space Used by Folders&lt;/A&gt; from my github:&amp;nbsp;&lt;A href="https://github.com/jthi-jmp-tools/file-indexer/tree/main" target="_self"&gt;jthi-jmp-tools/file-indexer (github)&lt;/A&gt;. It uses tree box and also has a search box. Other example of the search can be found from &lt;A href="https://community.jmp.com/t5/JMP-Add-Ins/JSL-Function-List/ta-p/67439" target="_blank" rel="noopener"&gt;JSL Function List add-in&lt;/A&gt; (I assume it is in Marketplace nowadays but I don't really use Marketplace it so I'm not sure). &lt;/P&gt;</description>
      <pubDate>Sat, 12 Apr 2025 10:04:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/867932#M103076</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-12T10:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868108#M103108</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I hope that after entering a keyword, only the items matching the keyword and their parent items will be displayed, as shown in the figure below. &lt;BR /&gt;For example, when I enter "water," the tree box will only show "watermelon" and its parent item "Fruit."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BabyDoragon_0-1744620167241.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/74834i4FADCE7C7DF41539/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BabyDoragon_0-1744620167241.png" alt="BabyDoragon_0-1744620167241.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2025 08:44:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868108#M103108</guid>
      <dc:creator>BabyDoragon</dc:creator>
      <dc:date>2025-04-14T08:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868111#M103110</link>
      <description>&lt;P&gt;Did you look at the examples I provided?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2025 09:06:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868111#M103110</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-14T09:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868683#M103141</link>
      <description>&lt;P&gt;The information in GitHub is too complicated... I can't understand the examples, I only know that the clue should be in the function `search_tree`.&lt;/P&gt;
&lt;P&gt;Could you please help provide a more straightforward example?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 07:47:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868683#M103141</guid>
      <dc:creator>BabyDoragon</dc:creator>
      <dc:date>2025-04-16T07:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868688#M103143</link>
      <description>&lt;P&gt;I don't remember if you were able to hide leaves without removing them, but you can at least dim them&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

root1 = Tree Node("Parent 1");
root2 = Tree Node("Parent 2");

c1 = Tree Node("Child 1");
c2 = Tree Node("Child 2");
c3 = Tree Node("Child 3");
c4 = Tree Node("Child 4");

root1 &amp;lt;&amp;lt; Append(c1);
root1 &amp;lt;&amp;lt; Append(c2);
root2 &amp;lt;&amp;lt; Append(c3);
root2 &amp;lt;&amp;lt; Append(c4);

nw = New Window("TreeBox",
	tree = Tree Box({root1, root2}, Size(300, 200))
);
tree &amp;lt;&amp;lt; Expand(root1);
tree &amp;lt;&amp;lt; Expand(root2);

search_term = " 1";

For Each({root}, tree &amp;lt;&amp;lt; get roots,
	is_hidden = 1;
	For(i = 1, i &amp;lt;= root &amp;lt;&amp;lt; Get Child Count, i++,
		cur_child = root &amp;lt;&amp;lt; get child(i);
		If(Contains(cur_child &amp;lt;&amp;lt; get label, search_term),
			tree &amp;lt;&amp;lt; make visible(cur_child);
			is_hidden = 0;
		,
			cur_child &amp;lt;&amp;lt; Set Dimmed(1);
		);
	);
	If(is_hidden,
		tree &amp;lt;&amp;lt; Collapse(root);
	,
		tree &amp;lt;&amp;lt; Expand(root);
	);
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on how complicated tree you have, you might want to look into recursion&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 08:18:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868688#M103143</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-16T08:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868689#M103144</link>
      <description>&lt;DIV data-container=""&gt;&lt;SPAN data-expression=""&gt;Dim is a good way to distinguish whether items meet the search keywords, but if the number of children is large, relying only on dimming their colors can make the search results hard to focus on. For example, when searching for the keyword "1" among the children from 1 to 100, the matching children like 1, 11-19, and 100 cannot be displayed prominently together. &lt;BR /&gt;It would be better if we could directly hide the child options compare to dim them. &lt;BR /&gt;Is there currently an effective way to directly hide non-matching child items like dim does?&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 16 Apr 2025 08:39:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868689#M103144</guid>
      <dc:creator>BabyDoragon</dc:creator>
      <dc:date>2025-04-16T08:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868694#M103146</link>
      <description>&lt;P&gt;Have you checked what Scripting Index offers for Tree Box() and Tree Node()?&amp;nbsp;If I remember correctly, you cannot hide nodes in Tree Box() so you have to use other methods of basically re-creating the tree with less nodes. This isn't too difficult to do but it will require extra JSL and some parameter management.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 09:34:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868694#M103146</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-16T09:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868696#M103147</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I want to proceed by removing nodes. Each time the keyword changes, I will remove the node again. For example, in JSL, the first keyword is 1, then it changes to 2, but it always ends up with an error. Why is that? According to this logic, how should I correct it?&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

root1 = Tree Node("Parent 1");
root2 = Tree Node("Parent 2");

c1 = Tree Node("Child 1");
c2 = Tree Node("Child 2");
c3 = Tree Node("Child 11");
c4 = Tree Node("Child 4");

root1 &amp;lt;&amp;lt; Append(c1);
root1 &amp;lt;&amp;lt; Append(c2);
root2 &amp;lt;&amp;lt; Append(c3);
root2 &amp;lt;&amp;lt; Append(c4);

nw = New Window("TreeBox",
	vlb = V List Box();
	
);
search_term = " 1";
tree = Tree Box({root1, root2}, Size(300, 200));
tree &amp;lt;&amp;lt; Expand(root1);
tree &amp;lt;&amp;lt; Expand(root2);
treeDuplicate=tree;
For Each({root}, treeDuplicate &amp;lt;&amp;lt; get roots,
	is_hidden = 1;
	For(i = 1, i &amp;lt;= root &amp;lt;&amp;lt; Get Child Count, i++,
		cur_child = root &amp;lt;&amp;lt; get child(i);
		If(Contains(cur_child &amp;lt;&amp;lt; get label, search_term),
			is_hidden = 0;
		,
			
			cur_child &amp;lt;&amp;lt; remove;
		);
	);
	If(is_hidden,
		treeDuplicate &amp;lt;&amp;lt; Collapse(root);
	,
		treeDuplicate &amp;lt;&amp;lt; Expand(root);
	);
);

vlb &amp;lt;&amp;lt; append(treeDuplicate );
wait(3);

treeDuplicate&amp;lt;&amp;lt; delete;

wait(3);
search_term = " 2";
treeDuplicate=tree;
For Each({root}, treeDuplicate &amp;lt;&amp;lt; get roots,
	is_hidden = 1;
	For(i = 1, i &amp;lt;= root &amp;lt;&amp;lt; Get Child Count, i++,
		cur_child = root &amp;lt;&amp;lt; get child(i);
		If(Contains(cur_child &amp;lt;&amp;lt; get label, search_term),
			is_hidden = 0;
		,
			
			cur_child &amp;lt;&amp;lt; remove;
		);
	);
	If(is_hidden,
		treeDuplicate &amp;lt;&amp;lt; Collapse(root);
	,
		treeDuplicate &amp;lt;&amp;lt; Expand(root);
	);
);
vlb &amp;lt;&amp;lt; append(treeDuplicate );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 10:36:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868696#M103147</guid>
      <dc:creator>BabyDoragon</dc:creator>
      <dc:date>2025-04-16T10:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868697#M103148</link>
      <description>&lt;P&gt;You are deleting the tree and you won't have access to it. Instead of duplicate = tree use cloning or other method of copying the display box structure. You have to make sure that all the nodes are also being cloned/copied over correctly and that they do not refer to same objects (copy vs deep copy).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

root1 = Tree Node("Parent 1");
root2 = Tree Node("Parent 2");

c1 = Tree Node("Child 1");
c2 = Tree Node("Child 2");
c3 = Tree Node("Child 11");
c4 = Tree Node("Child 4");

root1 &amp;lt;&amp;lt; Append(c1);
root1 &amp;lt;&amp;lt; Append(c2);
root2 &amp;lt;&amp;lt; Append(c3);
root2 &amp;lt;&amp;lt; Append(c4);

nw = New Window("TreeBox",
	vlb = V List Box();
	
);
tree = Tree Box({root1, root2}, Size(300, 200));
tree &amp;lt;&amp;lt; Expand(root1);
tree &amp;lt;&amp;lt; Expand(root2);

treeDuplicate = tree;
treeDuplicate1 = tree &amp;lt;&amp;lt; clone box;
show(
	treeDuplicate == tree, 
	treeDuplicate1 == tree,
	treeDuplicate &amp;lt;&amp;lt; get roots == tree &amp;lt;&amp;lt; get roots,
	treeDuplicate1 &amp;lt;&amp;lt; get roots == tree &amp;lt;&amp;lt; get roots
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;treeDuplicate == tree = 1;
treeDuplicate1 == tree = 0;
treeDuplicate &amp;lt;&amp;lt; get roots == tree &amp;lt;&amp;lt; get roots = 1;
treeDuplicate1 &amp;lt;&amp;lt; get roots == tree &amp;lt;&amp;lt; get roots = 1; //&amp;nbsp;be&amp;nbsp;careful&amp;nbsp;here&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Apr 2025 10:48:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868697#M103148</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-16T10:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868698#M103149</link>
      <description>&lt;DIV data-container=""&gt;&lt;SPAN data-expression=""&gt;The meaning seems to suggest that even if the Clone Box method is used, it cannot avoid the fact that when a copied tree node is removed, the original tree and its root are also removed. &lt;BR /&gt;This means that each time a keyword is changed, a new tree must be established, and then the nodes that match the keyword are removed. As a result, if there are many nodes, searching for keywords becomes very time-consuming in terms of computation.&lt;BR /&gt;&lt;BR /&gt;Are there any alternative methods to create a completely independent copy of the original tree?&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 16 Apr 2025 11:02:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868698#M103149</guid>
      <dc:creator>BabyDoragon</dc:creator>
      <dc:date>2025-04-16T11:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868699#M103150</link>
      <description>&lt;P&gt;You can go over the tree box and create copy "manually" (loop over the tree and build a copy) or rebuild it based on some other data structure (data table / associative array / your own custom class for example). Or you can try if there are methods to prevent this from happening by using expressions / functions.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 11:14:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868699#M103150</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-16T11:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868701#M103152</link>
      <description>&lt;P&gt;&lt;SPAN&gt;It seems that I can only regenerate a new tree each time. I changed it to the following JSL, and it works properly when the keyword is 1, but if I enter 2, 4, or something similar, it doesn't succeed. Could you please let me know what the problem might be?&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;root1 = Tree Node( "Parent 1" );
root2 = Tree Node( "Parent 2" );

c1 = Tree Node( "Child 1" );
c2 = Tree Node( "Child 2" );
c3 = Tree Node( "Child 11" );
c4 = Tree Node( "Child 4" );

filter_itemsSensorListTree = Function( {this, searchText},
	{filtered_items, i}, 
	// only attempt to filter if there is any text
	If( searchText != "",
		tree &amp;lt;&amp;lt; delete;
		search_term = searchText;
		root1 = Tree Node( "Parent 1" );
		root2 = Tree Node( "Parent 2" );

		c1 = Tree Node( "Child 1" );
		c2 = Tree Node( "Child 2" );
		c3 = Tree Node( "Child 11" );
		c4 = Tree Node( "Child 4" );
		root1 &amp;lt;&amp;lt; Append( c1 );
		root1 &amp;lt;&amp;lt; Append( c2 );
		root2 &amp;lt;&amp;lt; Append( c3 );
		root2 &amp;lt;&amp;lt; Append( c4 );
		tree = Tree Box( {root1, root2}, Size( 300, 200 ) );
		For Each( {root}, tree &amp;lt;&amp;lt; get roots,
			is_hidden = 1;
			For( i = 1, i &amp;lt;= root &amp;lt;&amp;lt; Get Child Count, i++,
				cur_child = root &amp;lt;&amp;lt; get child( i );
				If( Contains( cur_child &amp;lt;&amp;lt; get label, search_term ),
					is_hidden = 0, 
			
					cur_child &amp;lt;&amp;lt; remove
				);
			);
			If( is_hidden,
				tree &amp;lt;&amp;lt; Collapse( root ),
				tree &amp;lt;&amp;lt; Expand( root )
			);
		);
		vlb &amp;lt;&amp;lt; append( tree );
	, 
		
	);
	
);


root1 &amp;lt;&amp;lt; Append( c1 );
root1 &amp;lt;&amp;lt; Append( c2 );
root2 &amp;lt;&amp;lt; Append( c3 );
root2 &amp;lt;&amp;lt; Append( c4 );
tree = Tree Box( {root1, root2}, Size( 300, 200 ) );
tree &amp;lt;&amp;lt; Expand( root1 );
tree &amp;lt;&amp;lt; Expand( root2 );

nw = New Window( "TreeBox",
	H List Box(
		Icon Box( "SearchIndex" ),
		Spacer Box( size( 5, 10 ) ),
		item_search_teb_AllSensorTree = Text Edit Box( "",
			&amp;lt;&amp;lt;set width( 150 ), 

			&amp;lt;&amp;lt;set text changed( filter_itemsSensorListTree )
		),
		reset_button_AllSensorTree = Button Box( "",
			&amp;lt;&amp;lt;set icon( "DebuggerDeleteBreakpoint" ),
			&amp;lt;&amp;lt;set script(

				item_search_teb_AllSensorTree &amp;lt;&amp;lt; set text( "" );
				tree &amp;lt;&amp;lt; delete;
				root1 = Tree Node( "Parent 1" );
				root2 = Tree Node( "Parent 2" );

				c1 = Tree Node( "Child 1" );
				c2 = Tree Node( "Child 2" );
				c3 = Tree Node( "Child 11" );
				c4 = Tree Node( "Child 4" );
				root1 &amp;lt;&amp;lt; Append( c1 );
				root1 &amp;lt;&amp;lt; Append( c2 );
				root2 &amp;lt;&amp;lt; Append( c3 );
				root2 &amp;lt;&amp;lt; Append( c4 );
				tree = Tree Box( {root1, root2}, Size( 300, 200 ) );
				tree &amp;lt;&amp;lt; Expand( root1 );
				tree &amp;lt;&amp;lt; Expand( root2 );
				vlb &amp;lt;&amp;lt; append( tree );
			),
			&amp;lt;&amp;lt;set tip( "Clear filter" ), 

		),
		Spacer Box( size( 5, 10 ) ), 

	),
	vlb = V List Box( tree );
	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 12:24:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868701#M103152</guid>
      <dc:creator>BabyDoragon</dc:creator>
      <dc:date>2025-04-16T12:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868746#M103157</link>
      <description>&lt;P&gt;This very quick example might give some ideas&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

initialize_tree = function({}, {Default Local},
	root1 = Tree Node("Parent 1");
	root2 = Tree Node("Parent 2");

	c1 = Tree Node("Child 1");
	c2 = Tree Node("Child 2");
	c3 = Tree Node("Child 11");
	c4 = Tree Node("Child 4");
	root1 &amp;lt;&amp;lt; Append(c1);
	root1 &amp;lt;&amp;lt; Append(c2);
	root2 &amp;lt;&amp;lt; Append(c3);
	root2 &amp;lt;&amp;lt; Append(c4);
	tree = Tree Box({root1, root2}, Size(300, 200));
	
	tree &amp;lt;&amp;lt; Expand(root1);
	tree &amp;lt;&amp;lt; Expand(root2);
	
	return(tree);
);


filter_itemsSensorListTree = Function({vlb, search_term}, {Default Local}, 
	If(search_term != "", 
		new_tree = initialize_tree();
		For Each({root}, new_tree &amp;lt;&amp;lt; get roots,
			For(i = root &amp;lt;&amp;lt; Get Child Count, i &amp;gt;= 1 , i--,
				cur_child = root &amp;lt;&amp;lt; get child(i);
				If(Contains(cur_child &amp;lt;&amp;lt; get label, search_term),
					new_tree &amp;lt;&amp;lt; Make Visible(cur_child);
				,
					cur_child &amp;lt;&amp;lt; remove;
				);
			);
			If(root &amp;lt;&amp;lt; Get Child Count == 0,
				new_tree &amp;lt;&amp;lt; remove root(root);
			);
		);
	,
		new_tree = initialize_tree();
	);
	vlb_new = V List Box(new_tree);
	vlb &amp;lt;&amp;lt; Inval;
	(vlb &amp;lt;&amp;lt; Child) &amp;lt;&amp;lt; Delete Box();
	vlb &amp;lt;&amp;lt; Append(vlb_new);
	vlb &amp;lt;&amp;lt; Update Window;
);

nw = New Window( "TreeBox",
	H List Box(
		Icon Box( "SearchIndex" ),
		Spacer Box( size( 5, 10 ) ),
		item_search_teb_AllSensorTree = Text Edit Box("",
			&amp;lt;&amp;lt;set width( 150 ), 
			&amp;lt;&amp;lt;set function(function({this},
				filter_itemsSensorListTree(vlb, this &amp;lt;&amp;lt; get text)
			))
		),
		Spacer Box(size( 5, 10 )), 

	),
	vlb = V List Box(
		V List Box(
			initialize_tree()
		)
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2025 14:32:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/868746#M103157</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-16T14:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/869149#M103201</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I tried to change it to the following JSL. I want to get the label name by pressing a button after selecting a node. However, this results in an error when selecting a new option on the tree after entering keywords for filtering, possibly because `new_tree` is just a local variable. How should I fix it so that I can obtain the selected label from the new tree after the keyword search?&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

initialize_tree = Function( {},
	{Default Local},
	root1 = Tree Node( "Parent 1" );
	root2 = Tree Node( "Parent 2" );

	c1 = Tree Node( "Child 1" );
	c2 = Tree Node( "Child 2" );
	c3 = Tree Node( "Child 11" );
	c4 = Tree Node( "Child 4" );
	root1 &amp;lt;&amp;lt; Append( c1 );
	root1 &amp;lt;&amp;lt; Append( c2 );
	root2 &amp;lt;&amp;lt; Append( c3 );
	root2 &amp;lt;&amp;lt; Append( c4 );
	tree = Tree Box( {root1, root2}, Size( 300, 200 ) );
	
	tree &amp;lt;&amp;lt; Expand( root1 );
	tree &amp;lt;&amp;lt; Expand( root2 );
	
	Return( tree );
);


filter_itemsSensorListTree = Function( {vlb, search_term},
	{Default Local},
	If( search_term != "",
		new_tree = initialize_tree();
		For Each( {root}, new_tree &amp;lt;&amp;lt; get roots,
			For( i = root &amp;lt;&amp;lt; Get Child Count, i &amp;gt;= 1, i--,
				cur_child = root &amp;lt;&amp;lt; get child( i );
				If( Contains( cur_child &amp;lt;&amp;lt; get label, search_term ),
					new_tree &amp;lt;&amp;lt; Make Visible( cur_child ),
					cur_child &amp;lt;&amp;lt; remove
				);
			);
			If( root &amp;lt;&amp;lt; Get Child Count == 0,
				new_tree &amp;lt;&amp;lt; remove root( root )
			);
		);
	,
		new_tree = initialize_tree()
	);
	vlb_new = V List Box( new_tree );
	vlb &amp;lt;&amp;lt; Inval;
	(vlb &amp;lt;&amp;lt; Child) &amp;lt;&amp;lt; Delete Box();
	vlb &amp;lt;&amp;lt; Append( vlb_new );
	vlb &amp;lt;&amp;lt; Update Window;
);

nw = New Window( "TreeBox",
	H List Box(
		Icon Box( "SearchIndex" ),
		Spacer Box( size( 5, 10 ) ),
		item_search_teb_AllSensorTree = Text Edit Box( "",
			&amp;lt;&amp;lt;set width( 150 ),
			&amp;lt;&amp;lt;set function( Function( {this}, filter_itemsSensorListTree( vlb, this &amp;lt;&amp;lt; get text ) ) )
		),
		Spacer Box( size( 5, 10 ) ), 

	),
	vlb = V List Box( V List Box( tree=initialize_tree() ) ),
	Button Box( "Select", 						
		SelectNode = (tree &amp;lt;&amp;lt; GetSelected) &amp;lt;&amp;lt; Get label;
		try (ShowText&amp;lt;&amp;lt;delete);
		VLB2&amp;lt;&amp;lt;Append(ShowText=Text Box( SelectNode ));
	),
	VLB2=vlistbox(),
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Apr 2025 07:24:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/869149#M103201</guid>
      <dc:creator>BabyDoragon</dc:creator>
      <dc:date>2025-04-18T07:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in Tree box</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/869151#M103202</link>
      <description>&lt;P&gt;Your Button Box is referencing wrong display box as the tree it is referencing to has been deleted. There are good ways around this via updating the reference but you can also make it dynamic and always look for the latest tree box inside vlb for example.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Button Box("Select",
	label_selected = (vlb[TreeBox(1)] &amp;lt;&amp;lt; get selected) &amp;lt;&amp;lt; get label;
	Try(ShowText &amp;lt;&amp;lt; delete);
	VLB2 &amp;lt;&amp;lt; Append(ShowText = Text Box(label_selected));
),
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Apr 2025 07:56:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-Tree-box/m-p/869151#M103202</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-18T07:56:24Z</dc:date>
    </item>
  </channel>
</rss>

