So, 3.5.4 is available through the auto update, so time to shed some light on the new abilities of the DBTreeView bean, because the bean received an major overhaul and all of this will only appear in the 4.0 documentation, which will not be available until 4.0 will be released.
To start with, it is not just the DBTreeView bean anymore, it is also the DBTreeTableView bean. Yes, you can now also have a tree with multiple columns!
And in both beans, you can build up the tree to collect childnodes from different tables. So, for example, you can go from Companies to Customers to Orders to OrderLines. The sky is the limit
Now, you may ask yourself: “does this work in the web as well?”. To that I can only say: YES! Ok, but what about automatically keeping in sync with datachanges, new records and the likes? Yes, that works as well. Also in the web?!?! Once again: Yes!!
So, how does it work? Basically, you still set the rootNodes by supplying a foundset. But then it differs from the old bean: You have to create a so called “binding” to a table. You bind a bean to a table and in the binding you provide information where to get the details how to render nodes that come from that table. You can bind the bean to mulitple tables but a table can only be binded to the bean once. Am I still making sense? Example please…
Example 1:
Place a DBTreeView bean on your form and name it bean_1.
var _binding = elements.bean_1.createBinding(controller.getServerName(), controller.getTableName());
_binding.setImageURLDataprovider("X"); //Replace X with the name of a dataprovider that returns a URL that points to an Image
_binding.setChildSortDataprovider("X"); //Replace X with the name of a dataprovider that returns a sort string
_binding.setHasCheckBoxDataprovider("X"); //Replace X with the name of a dataprovider that returns a boolean value to indicate whether to render the Node with a CheckBox or not
_binding.setCheckBoxValueDataprovider("X"); //Replace X with the name of a dataprovider that is linked to the checkbox
_binding.setNRelationName("X"); //Replace X with the name of the relation that supplied the childNodes for a Node
_binding.setTextDataprovider("X"); //Replace X with the name of a dataprovider that returns the text for the node
_binding.setMethodToCallOnClick(globals.XXXX, "X"); //Sets the global method that gets called when the node is clicked and replace X with the name of a dataprovider will be send as an argument into the globals.XXX method (note: no "()" behind "globals.XXXX")
controller.find();
column_x = "someValueHere";
controller.search(true,true);
elements.bean_1.addRoots(foundset);
That is all! In the attached example solution you will find a setup as above for the bean on the upper left corner of the form. Noticed that there is a function called “setHasCheckBoxDataprovider”? With that you can determine whether or not to have a checkbox rendered on each node. Is that cool or what?
Note: The sample solution is based on the UDM database. For the bean to show a hierargy, you will need to set the hierargy in the Companies form. Make sure 1 company does not get a Parent Company, or else there will not be any rootNodes in the tree.
Example 2:
Now the next step is to link in multiple tables. How do we accomplish this? Easy! First, per table that we want to link in, we create a binding as described above. You call the createBinding function on the bean and supply the Server- and TableName for which you want to create the binding. As said before: You can only bind a table once to a bean, but a bean can have bindings to multiple tables.
Now, how do we get the bean to read the childNodes from a different table: “_binding.setNRelationDataprovider(”#“);” is your friend. Just replace the # by the name of a dataprovider that returns the name of a relation that will get you the childNodes. Offcourse, you have to have a binding for the table on the right hand side of the relation (that side holding the childNodes) to the bean as well, otherwise the bean does not know how to render the childNodes.
An example of this setup can be found in the lower left corner on the first form of the sample solution.
Example 3:
Ok, so we have a DBTreeView bean with checkboxes and nodes from multiple tables. What about the TreeTable stuff? Well, once again it is not so complicated. instead of placing a DBTreeView bena on our form, we place a DBTreeTableView bean on out form. If you look at the bean in the Method Editor, you will see there is a new subnode called “Column” and a few extra functions, but otherwise, it has a pretty similar API as the regular DBTreeView bean. So, how do we get this TreeTable stuff going? By adding columns…
On the bean, there is a function called “createColumn(servername, tablename, header, fieldname);”. The use is pretty straight forward: You can add columns of the tables you also have created a binding for for this bean. You just specify the serverName, tableName, the header text for the column and the dataprovider name (columnName in the database) and the column will be added to the bean. On a Node in the Tree that comes from that table, the column will be rendered with the data from the dataprovider you specified.
In the attached solution, the two beans on the right are Treetable beans: the upper one takes all nodes from 1 table, the one on the bottom takes its nodes from different tables.
So, that is all the new functionality in a nutshell. Review the sample solution, play around with it, modify is and start using the beans to create some interesting GUI’s curious to see the results in Vegas…
Regards,
Paul
TreeBeanSample.servoy (77.3 KB)