# Help with DBTreeView from ServoyExtraComponents

**URL:** <https://forum.servoy.com/t/help-with-dbtreeview-from-servoyextracomponents/20887>\
**Category:** Questions\
**Created:** [October 21, 2022, 2:06pm UTC](https://forum.servoy.com/t/help-with-dbtreeview-from-servoyextracomponents/20887 "2022-10-21T14:06:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfernandez](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@dfernandez](https://forum.servoy.com/u/dfernandez)\
**Post date:** [October 21, 2022, 2:06pm UTC](https://forum.servoy.com/t/help-with-dbtreeview-from-servoyextracomponents/20887/1 "2022-10-21T14:06:11Z")

</div>

Hi all,

I am trying to understand how to use the DBTreeView to work with 3 levels. I can show the data with no problem but there is a problem with the third level when I click on it because it is not returning the right record id for it. I tried different forms to do the setNRelationName. The one running now shows the correct info in the tree but the setCallBackInfo method returns the id of the first level, the id of the second one and repeats the second id in the third one:  
var myselected =   
myselected = elements.dbtreeview\_1.getSelectionPath()  
application.output(myselected)  
{EASTC,10400,10400}

This is the initialization code for the DBTreeView:

elements.dbtreeview\_1.addRoots(foundset)  
elements.dbtreeview\_1.setTextDataprovider(controller.getDataSource(), ‘companyname’);

elements.dbtreeview\_1.setNRelationName(controller.getDataSource(), ‘customers\_to\_orders’);  
elements.dbtreeview\_1.setTextDataprovider(databaseManager.getDataSource(‘example\_data’, ‘orders’),‘orderid’)

elements.dbtreeview\_1.setNRelationName(databaseManager.getDataSource(‘example\_data’, ‘orders’),‘orders\_to\_order\_details’);  
// elements.dbtreeview\_1.setNRelationName(databaseManager.getDataSource(‘example\_data’, ‘order\_details’),‘customers\_to\_orders.orders\_to\_order\_details’);  
elements.dbtreeview\_1.setTextDataprovider(databaseManager.getDataSource(‘example\_data’, ‘order\_details’),‘unitprice’)

//set the method to call and dataprovider value to pass when node clicked  
elements.dbtreeview\_1.setCallBackInfo(controller.getDataSource(), rootselected,‘companyname’);  
elements.dbtreeview\_1.setCallBackInfo(databaseManager.getDataSource(‘example\_data’, ‘orders’),mediumselected,‘orderid’)  
elements.dbtreeview\_1.setCallBackInfo(databaseManager.getDataSource(‘example\_data’, ‘order\_details’),thirdselected,‘productid’);

Any sample on how to use this control will help.

Thanks!

---

<div class="post-metadata">

**Author:** ![Gabi\_Boros](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@Gabi\_Boros](https://forum.servoy.com/u/Gabi_Boros)\
**Post date:** [October 25, 2022, 1:54pm UTC](https://forum.servoy.com/t/help-with-dbtreeview-from-servoyextracomponents/20887/2 "2022-10-25T13:54:47Z")

</div>

your code is correct, the problem seems to be that ‘order\_details’ has 2 pks, orderid and productid, and dbtreeview will return the first one, that is why, you get the same id on the third level as on the second

---

<div class="post-metadata">

**Author:** ![dfernandez](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@dfernandez](https://forum.servoy.com/u/dfernandez)\
**Post date:** [October 25, 2022, 2:10pm UTC](https://forum.servoy.com/t/help-with-dbtreeview-from-servoyextracomponents/20887/3 "2022-10-25T14:10:46Z")

</div>

Thank you so much Gabi!

---

<div class="post-metadata">

**Author:** ![dfernandez](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@dfernandez](https://forum.servoy.com/u/dfernandez)\
**Post date:** [October 25, 2022, 5:10pm UTC](https://forum.servoy.com/t/help-with-dbtreeview-from-servoyextracomponents/20887/4 "2022-10-25T17:10:21Z")

</div>

How do you sort the text in each level?  
elements.dbtreeview\_1.setChildSortDataprovider after elements.dbtreeview\_1.setTextDataprovider is not working.

i.e.:  
elements.dbtreeview\_1.setNRelationName(controller.getDataSource(), ‘customers\_to\_orders’);  
elements.dbtreeview\_1.setTextDataprovider(databaseManager.getDataSource(‘example\_data’, ‘orders’),‘orderid’)  
elements.dbtreeview\_1.setChildSortDataprovider(databaseManager.getDataSource(‘example\_data’, ‘orders’),‘orderid’)

Thanks

---

<div class="post-metadata">

**Author:** ![Gabi\_Boros](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@Gabi\_Boros](https://forum.servoy.com/u/Gabi_Boros)\
**Post date:** [October 26, 2022, 7:04am UTC](https://forum.servoy.com/t/help-with-dbtreeview-from-servoyextracomponents/20887/5 "2022-10-26T07:04:48Z")

</div>

To set the sorting of the child nodes from orders, you need to have the sorting string in the parent record as a dataprovider (in the customers table).  
As an example, you can define a calculation field in the customers table, lets say, ‘mysort’, that returns the sort string you want to apply on that row’s child nodes (from orders), let’s say it returns ‘orderid asc’.  
Then in the script, you will set the sorting with: elements.dbtreeview\_1.setChildSortDataprovider(databaseManager.getDataSource(‘example\_data’, ‘customers’),‘mysort’) - so, you set the sort dataprovider in the parent datasource.

---

<div class="post-metadata">

**Author:** ![dfernandez](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@dfernandez](https://forum.servoy.com/u/dfernandez)\
**Post date:** [October 26, 2022, 1:55pm UTC](https://forum.servoy.com/t/help-with-dbtreeview-from-servoyextracomponents/20887/6 "2022-10-26T13:55:11Z")

</div>

Thank you Gabi!
