# Treeview question

**URL:** <https://forum.servoy.com/t/treeview-question/13141>\
**Category:** Classic Servoy\
**Created:** [November 3, 2010, 7:18am UTC](https://forum.servoy.com/t/treeview-question/13141 "2010-11-03T07:18:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichelvGent](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MichelvGent](https://forum.servoy.com/u/MichelvGent)\
**Post date:** [November 3, 2010, 7:18am UTC](https://forum.servoy.com/t/treeview-question/13141/1 "2010-11-03T07:18:36Z")

</div>

OK, I’ve been reading about the treeview bean but it looks like what I want to do is not possible ![:(]( "Sad")

But before I’m going to look for another solution, I thought I’d post what I need/want to do here firts:  
I have a form (data provider is not table I need for the tree).

I have (lets say) customers. Customers can have documents. (Cus to cus\_doc and cus\_doc to doc). In the tree I want to display a node called docs showing the numer of docs found for this customer usesing customer\_id. Clicking on the + will show the docs.

Customers also have communication records. (Cus to comm and comm to commtype). I’d like to show a new node in the same treeview with the communication. Showing them by type with the amount of records found.

Customers also have contacts, cus to contact. So I want to show a new node in the same tree showing the amount of records found. Display the names when hitting the + and one level deeper, the adres(ses) by type same as comm.

Example of how it should look like:

```auto
+ Docs (2)
	o Document_1
	o Document_2
+ Comm (3)
	+ Email (2)
		o test@email.com
		o test2@email.com
	+ GSM (2)
		o 06-12345678
		o 06-98765432
	+ Fax (1)
		o 1234-567890
+ Contacts (2)
	+ Mike (1)
		+ Home (1)
			o streetname 2 1234AA city
	+ Jan (2)
		+ Home(1)
			o streetname 6 1234AA city
		+ Work(1)
			o street 16 3422FF Newcity

```

Is this possible?

Thanks in advance.

Michel

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [November 3, 2010, 7:55am UTC](https://forum.servoy.com/t/treeview-question/13141/2 "2010-11-03T07:55:29Z")

</div>

Hi Michel,

which TreeView bean are we talking about?

- the one Servoy ships by default?
- the extended one, found here: [http://www.servoy.com/downloads/downloads/bean\_plugin/treeview\_plugin.zip](http://www.servoy.com/downloads/downloads/bean_plugin/treeview_plugin.zip)

The default TreeView bean is limited to showing data from tables, which - in the situation you describe - doesn’t seem very suitable.  
The extended TreeView bean can show data based on a dataset and that’s exactly the flexibility you need.

So the only thing you really need is a correctly build dataset and show it.  
You have to keep in mind: the root nodes do not exist in your database, based on the existence of related docs/comm/contacts you can choose to add/skip those.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![MichelvGent](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MichelvGent](https://forum.servoy.com/u/MichelvGent)\
**Post date:** [November 3, 2010, 8:04am UTC](https://forum.servoy.com/t/treeview-question/13141/3 "2010-11-03T08:04:15Z")

</div>

So there is an extended one ![:D]( "Very Happy")

Thanks, I’ll check this out.

---

<div class="post-metadata">

**Author:** ![MichelvGent](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MichelvGent](https://forum.servoy.com/u/MichelvGent)\
**Post date:** [November 3, 2010, 1:05pm UTC](https://forum.servoy.com/t/treeview-question/13141/4 "2010-11-03T13:05:52Z")

</div>

Hi Marc,

Looks like this is what I need.

Does anyone have a simple small code example. Somehow I can’t import the sample solution.

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [November 3, 2010, 3:13pm UTC](https://forum.servoy.com/t/treeview-question/13141/5 "2010-11-03T15:13:48Z")

</div>

> MichelvGent:  
> Does anyone have a simple small code example.

Didn’t take a very close look, but this is what we use:

```auto
//	Create empty dataset for treeview
	var $newDs = databaseManager.createEmptyDataSet(0,['id', 'pid', 'treeColumn', 'icon', 'editable']);
	$newDs.addRow([_pk, _parentPk, _nodeName, nodeIcon, 'false'])
	//repeat the above line for other nodes

	elements.tree.setDataSet($newDs);
	elements.tree.setHeaderVisible(false);
	elements.tree.setColumnWidth('treeColumn', 200);
	elements.tree.onNodeClicked(onClick);
	elements.tree.onNodeIconClicked(onClick);
	elements.tree.expandNode(1);

```

for the root-nodes (your Docs/Comm/Contacts) the \_parentPk should be ‘null’.

The ‘onClick’ references to a formmethod like:

```auto
function onClick(pk)
{
     // do something with the pk...
}

```

I think this will get you started…

---

<div class="post-metadata">

**Author:** ![MichelvGent](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MichelvGent](https://forum.servoy.com/u/MichelvGent)\
**Post date:** [November 4, 2010, 8:15am UTC](https://forum.servoy.com/t/treeview-question/13141/6 "2010-11-04T08:15:04Z")

</div>

Thanks again. Works great!

The id and pid don’t need to be an int, am I correct?  
This really makes it very easy to build a multilevel tree.

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [November 4, 2010, 9:19am UTC](https://forum.servoy.com/t/treeview-question/13141/7 "2010-11-04T09:19:41Z")

</div>

> MichelvGent:  
> The id and pid don’t need to be an int, am I correct?

That’s correct, this was a constrain in an earlier version.  
We requested a change for this as we only use(d) UUID’s and this was implemented shortly after that.  
The version you downloaded does already has this change, so you should be able to use just anything.

---

<div class="post-metadata">

**Author:** ![MichelvGent](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MichelvGent](https://forum.servoy.com/u/MichelvGent)\
**Post date:** [November 4, 2010, 11:47am UTC](https://forum.servoy.com/t/treeview-question/13141/8 "2010-11-04T11:47:02Z")

</div>

Wow, I really like treeview bean.

I see there options:  
elements.tree.onNodeRightClicked(onRightClick);  
elements.tree.onNodeIconClicked(onClick);

And I think it would be real cool if there was a option:

elements.tree.onNodeDoubleClicked(onDoubleClick);

![:D]( "Very Happy")

Well, who knows in the future.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [November 4, 2010, 11:59am UTC](https://forum.servoy.com/t/treeview-question/13141/9 "2010-11-04T11:59:18Z")

</div>

> MichelvGent:  
> And I think it would be real cool if there was a option:
> 
> elements.tree.onNodeDoubleClicked(onDoubleClick);
> 
> ![:D]( "Very Happy")
> 
> Well, who knows in the future.

So did you file a feature request for it ?

---

<div class="post-metadata">

**Author:** ![MichelvGent](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MichelvGent](https://forum.servoy.com/u/MichelvGent)\
**Post date:** [November 4, 2010, 2:17pm UTC](https://forum.servoy.com/t/treeview-question/13141/10 "2010-11-04T14:17:11Z")

</div>

I did now

![:D]( "Very Happy")
