3.5.4 DBTreeView bean: how to use the new functionality

Thanks for pointing me to the slides, Robert - wish I could’ve been at your session at ServoyWorld! :(

Also filed a feature request - ‘160199 - DBTreeView bean - Have the option to make the checkbox non-editable’.

Cheers,

Ben

Can anyone tell me what the difference is between

setNRelationName and setMRelationName ?

it is the equivalent of nested “where” in SQL, if you know SQL.
so it is a parent to grand’children relationship.

I know SQL but I don’t understand what you are trying to explain me.
Can you give an example?

The setNRelationName is clear to me. I get the child records like expected.

But what is the setMRelationName doing to this bean?
And can you use both or always N or M?

I thought you were talking generally.
in the treeview, I don’t use the M one, but 2 N relationships if more than 2 nodes are required.
According to Roclasi docs, the M one is used when you want the node to show a n to n relationship done through a 3rd table (for example, N customers visited by N engineers would need a N relation for customers to customers_engineers_visits and a M relationship from customers_engineers_visits to engineers. technically interesting though its usage is rare in a treeview, I have never used it this way, and you probably can forget the M relationship when starting using the treeview, and try that at a later stage.

Hi Martin,

Did you take a look at the slides I mentioned earlier in this thread.
It has 2 slides that pretty much explains what it is and how to use it.
In short it’s used when you have nodes that can have multiple parents and multiple children. I.e. n-m relations.

Hope this helps.

hi,

i have 5 table to show into my DBTreeView

the table A is the master table/root a.id
the table B is a child of table A rel_id = a.id
the table C is a child of table A rel_id = a.id
the table D is a child of table C rel_id = c.id
the table E is a child of table C rel_id = c.id

the A node contain B and C
the C node contain E and E

i’ve try to do this following the documentation:

var _table_a = elements.three.createBinding('myServer','table_a');
var _table_b = elements.three.createBinding('myServer','table_b');
var _table_c = elements.three.createBinding('myServer','table_c');
var _table_d = elements.three.createBinding('myServer','table_d');
var _table_e = elements.three.createBinding('myServer','table_e');

  _table_a.setTextDataprovider('display_value')
  _table_b.setTextDataprovider('display_value');
  _table_c.setTextDataprovider('display_value');
  _table_d.setTextDataprovider('display_value');
  _table_e.setTextDataprovider('display_value');

 _table_a.setNRelationName('table_a_to_table_b')
 _table_b.setNRelationDataprovider('table_a_to_table_b')
 _table_a.setNRelationName('table_a_to_table_c')
 _table_c.setNRelationDataprovider('table_a_to_table_c')
 _table_c.setNRelationName('table_c_to_table_d')
 _table_d.setNRelationDataprovider('table_c_to_table_d')	 
 _table_c.setNRelationName('table_c_to_table_e')
 _table_e.setNRelationDataprovider('table_c_to_table_e')		
    
	 var _foundset = databaseManager.getFoundSet('myServer','table_a');
	_foundset.loadRecords();
	elements.three.addRoots(_foundset);

but it doesen’t work completely,only first node appear

anyone can help me please?

thanks

Marco

Hello,

I have a big issue with this bean! Does it have support for internationalization?

I have something like this

var $binding = elements.bean_contents.createBinding(controller.getServerName(), controller.getTableName())
$binding.setChildSortDataprovider(‘navigation_id’)
$binding.setNRelationName(‘nav_navigation_to_nav_navigation’);

$binding.setTextDataprovider(‘nav_text’);

in my case nav_text is a key for a i18n value? Is it possible to get the i18n value instead of the key?

Please help me! This is urgent!

Thank you

Yes,

Make your column nav_text a calculation.
And put in the databasefield the i18n-key

And your calculation should look like:

		var _label = i18n.getI18NMessage(utils.stringReplace(yourDatabaseField, 'i18n:', ''))
		
		if(_label == '')
		{
			_label = yourDatabaseField
		}
		
		return _label;

What I do here, is that yourDatabaseField can contain a fixed value or an i18n-key
I check if it is an i18n key, in that case it returns the translated value
If it is not an i18n-key, it returns the database value

It works!

Thank you very much for your detailed and fast response!

I have another question if you could help me!

My bean is filled with data using a recursive relation (id → parent_id)

is there a way when I click a node to get all the subnodes…in an array or dataset or something?

I need to get all the children of a node!

Thank you very much!

Just use the relation parent → child to build your tree.

That works. I do the same.
No arrays or datasets. Just bind over the relation

I do not understand what you mean…

I have a tree like this

a
|–ab

–abd
±-±-abc

I need to get all the subnodes of node a!

How do I do that? I need to get those nodes when I click on node a

Thank you very much

What version of Servoy are you using?

I use 3.5.10

Is your relation correct?

nav_navigation to nav_navigation
menu_id to parent_menu_id

Determine your root in nav_navigation (these are menu_id’s without parent_id)

And load the root elements

elements.dbtreeview.addRoots(foundset)

If you do it like this it should work (it works for me, to show menus and submenus)

Hello,

Yes it loads the data correctly!

But this bean has a method

$binding.setMethodToCallOnClick(forms.nav_help_main_contents.treeClick, ‘navigation_id’);

what I want is that when an item is clicked in the tree (a node that has children) I would like to get the list of those children.

if a node has 3 children I would like to get them (this taking place in the treeClick method). Is that possible?

Try to use a global method and do the stuff you want to do from the globis method.
Maybe you have some problem with that method on that form (foundset sharing)

Also check if the id you get is the lowest level in the tree. If not, perhaps you want to skip that coding and just open the subtree

well, here it is a solution to this problem!

I get in the treeClick method the pk of nav_navigation table

and I wrote a recursive query to get all the chlidren of that node and all the information of that node (exactly like in a folder structure, I want to get all the subfolders of a parent folder)

Thanks a lot for your time! :)

Hello,

I hope this is the last question!

Is there a way to sort the parent nodes by a criteria?

A method like setChildSortDataprovider(‘sort_order’) but for parents?

Thanks a lot!