Help with DBTreeView from ServoyExtraComponents

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Help with DBTreeView from ServoyExtraComponents

Postby dfernandez » Fri Oct 21, 2022 4:06 pm

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!
dfernandez
 
Posts: 85
Joined: Wed Feb 29, 2012 4:04 pm

Re: Help with DBTreeView from ServoyExtraComponents

Postby Gabi Boros » Tue Oct 25, 2022 3:54 pm

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
Gabi Boros
Servoy
Gabi Boros
 
Posts: 399
Joined: Tue Jun 26, 2007 4:03 pm
Location: Timisoara, Romania

Re: Help with DBTreeView from ServoyExtraComponents

Postby dfernandez » Tue Oct 25, 2022 4:10 pm

Thank you so much Gabi!
dfernandez
 
Posts: 85
Joined: Wed Feb 29, 2012 4:04 pm

Re: Help with DBTreeView from ServoyExtraComponents

Postby dfernandez » Tue Oct 25, 2022 7:10 pm

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
dfernandez
 
Posts: 85
Joined: Wed Feb 29, 2012 4:04 pm

Re: Help with DBTreeView from ServoyExtraComponents

Postby Gabi Boros » Wed Oct 26, 2022 9:04 am

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.
Gabi Boros
Servoy
Gabi Boros
 
Posts: 399
Joined: Tue Jun 26, 2007 4:03 pm
Location: Timisoara, Romania

Re: Help with DBTreeView from ServoyExtraComponents

Postby dfernandez » Wed Oct 26, 2022 3:55 pm

Thank you Gabi!
dfernandez
 
Posts: 85
Joined: Wed Feb 29, 2012 4:04 pm


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests

cron