Hello everyone,
I am using the DBTreeView bean and want to prevent the nodes from being re-sorted when another form sorts the data that was used to create the Tree. The initialization code for the DBTreeView bean is posted below.
function onLoad()
{
var servername = databaseManager.getDataSourceServerName(controller.getDataSource());
var tablename = databaseManager.getDataSourceTableName(controller.getDataSource());
var _binding;
_binding = elements.school_hierarchy_tree.createBinding(servername, tablename);
_binding.setImageURLDataprovider('school_icon');
_binding.setNRelationDataprovider('n_relation');
_binding.setTextDataprovider('name');
_binding.setCallBackInfo(node_selected,'school_id');
_binding = elements.school_hierarchy_tree.createBinding(servername, 'buildings');
_binding.setImageURLDataprovider('building_icon');
_binding.setNRelationDataprovider('n_relation');
_binding.setTextDataprovider('name');
_binding.setCallBackInfo(node_selected,'building_id');
_binding = elements.school_hierarchy_tree.createBinding(servername, 'spaces');
_binding.setImageURLDataprovider('space_icon');
_binding.setNRelationDataprovider('n_relation');
_binding.setTextDataprovider('name');
_binding.setCallBackInfo(node_selected,'space_id');
_binding = elements.school_hierarchy_tree.createBinding(servername, 'elements');
_binding.setImageURLDataprovider('element_icon');
_binding.setTextDataprovider('name');
_binding.setCallBackInfo(node_selected,'element_id');
var _fs = databaseManager.getFoundSet(servername, tablename);
_fs.loadRecords();
elements.school_hierarchy_tree.addRoots(_fs);
}
Now the problem occurs when another form contains a sortable table (like a portal) that allows the user to change the sorting any of the columns. This has the effect that the affected nodes on the tree get sorted too! I really want to keep the DBTreeView navigation totally independent from the rest of the application so I tried using the unrelate() function to create a copy of the foundset and use that copy in “addRoots(unrelatedFoundset)”, but this had no effect.
For completeness sake and because I appreciated the examples in the other posts on the DBTreeView so much, here is also the code for handling callBacks and selecting Records in the foundset:
function node_selected(arg0)
{
//Select Records based on selection Path of Tree Node
var path = elements.school_hierarchy_tree.selectionPath;
if(path[0])foundset.selectRecord(path[0]);//school
if(path[1])foundset.schools_to_buildings.selectRecord(path[1]);//building
if(path[2])foundset.schools_to_buildings.buildings_to_spaces.selectRecord(path[2]);//space
if(path[3])foundset.schools_to_buildings.buildings_to_spaces.spaces_to_elements.selectRecord(path[3]);//element
//Switch the Form display depending on the type of Node clicked
switch(path.length){
case 1:
forms.mainTabs.elements.tabLayout.setRightForm('frm_buildings', 'schools_to_buildings');
break;
case 2:
forms.mainTabs.elements.tabLayout.setRightForm('frm_spaces', 'schools_to_buildings.buildings_to_spaces');
break;
case 3:
forms.mainTabs.elements.tabLayout.setRightForm('frm_elements', 'schools_to_buildings.buildings_to_spaces.spaces_to_elements');
break;
case 4:
forms.mainTabs.elements.tabLayout.setRightForm('frm_elements', 'schools_to_buildings.buildings_to_spaces.spaces_to_elements');
break;
}
}
Note that I use Record selection instead of searches (as is the case in the TreeBeanSample example provided by Servoy). Since the selectionPath property of the tree handily contains the private keys of the records I also ignore the callback values (arg0) and effectively simply (ab)use the callback as an event listener (please tell me if this is really bad!).
I also found that it is now possible to directly call the local function for the callback instead of going the long way via the Global function call. Thus the comment from the sample “//since the dbtreeview only can call global methods,we forward the call to a specific form” seems outdated.
I hope someone can help me with the sorting problem and that the code I posted is helpful to others. Thanks up front to anyone replying and to the Servoy Dev team.
Micah
This is Servoy Developer Version 6.0.1 build 1219.