Page 1 of 1

Help with DBTreeView from ServoyExtraComponents

PostPosted: Fri Oct 21, 2022 4:06 pm
by dfernandez
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!

Re: Help with DBTreeView from ServoyExtraComponents

PostPosted: Tue Oct 25, 2022 3:54 pm
by Gabi Boros
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

Re: Help with DBTreeView from ServoyExtraComponents

PostPosted: Tue Oct 25, 2022 4:10 pm
by dfernandez
Thank you so much Gabi!

Re: Help with DBTreeView from ServoyExtraComponents

PostPosted: Tue Oct 25, 2022 7:10 pm
by dfernandez
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

Re: Help with DBTreeView from ServoyExtraComponents

PostPosted: Wed Oct 26, 2022 9:04 am
by Gabi Boros
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.

Re: Help with DBTreeView from ServoyExtraComponents

PostPosted: Wed Oct 26, 2022 3:55 pm
by dfernandez
Thank you Gabi!