Treeview question

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

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:

+ 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

Hi Michel,

which TreeView bean are we talking about?

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.

So there is an extended one :D

Thanks, I’ll check this out.

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.

MichelvGent:
Does anyone have a simple small code example.

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

//	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:

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

I think this will get you started…

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.

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.

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

Well, who knows in the future.

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

elements.tree.onNodeDoubleClicked(onDoubleClick);

:D

Well, who knows in the future.

So did you file a feature request for it ?

I did now

:D