How to merge some of trees in one Accordion?

Hi,

I have some trees in the accordion. I have some questions for this topic.
q1 : How to merge duplicated code of some trees in the accordion?
q2 : How to have a method to load different tree.loadXML shortly?
thank you.

Codes:
var tree = dhxAccord.cells(“administration”).attachTree();
tree.setSkin(“dhx_skyblue”);
tree.setImagePath(“dht/tree/codebase/imgs/csh_vista/”);
tree.loadXML(“xml/hr-accessLevel3.xml”);

	    var tree = dhxAccord.cells("user_management").attachTree();
	    tree.setSkin("dhx_skyblue");
	    tree.setImagePath("dht/tree/codebase/imgs/csh_vista/");
	    tree.loadXML("xml/admin_tree.xml");
	    tree.setOnClickHandler(userManagement);
	    
	   var tree = dhxAccord.cells("phonebook").attachTree();
	    tree.setSkin("dhx_skyblue");
	    tree.setImagePath("dht/tree/codebase/imgs/csh_vista/");
	    tree.loadXML("xml/phonebook-hk.xml");
	    tree.setOnClickHandler(phoneBookToClick);

Hi
You can use the next approach:

function createTree(cellId,xml,onClickH){
//cellId - id of accordion cell, xml - path to xml file, onClickH - your onClick handler
var tree = acc.cells(cellId).attachTree();
tree.setSkin(“dhx_skyblue”);
tree.setImagePath(“dht/tree/codebase/imgs/csh_vista/”);
tree.loadXML(xml);
if(onClickH)
tree.attachEvent(“onClick”,onClickH);
return tree;
}
var tree1 = createTree(“cellA”,“myxml1.xml”,null);
var tree2 = createTree(“cellB”,“myxml2.xml”,func1);
var tree2 = createTree(“cellC”,“myxml3.xml”,func2);
// func1 & func2 - your custom functions like ‘userManagement’ & ‘phoneBookToClick’

Hi ,

Thank you for your reply this post.

The same function of createTree can read xml for accordion, but the function1 & function2 can not read data from database.

var tree1 = createTree(“administration”,“xml/hr-accessLevel3.xml”,null);
var tree2 = createTree(“user_management”,“xml/admin_tree.xml”,userManagement);
var tree3 = createTree(“phonebook”,“xml/phonebook-hk.xml”,phoneBookToClick);

function 1 & 2:
function phoneBookToClick(id){
if(tree.getItemText(id) == “GFHK”){
dhxGrid.loadXML(“lib/get_phone.php?location=hk&dept=”);
dhxGrid.init();
}else if(tree.getItemText(id) == “TEAM A”){
//alert(“success”);
dhxGrid.loadXML(“lib/get_phone.php?location=hk&dept=team a”);
dhxGrid.init();
}
else if(tree.getItemText(id) == “TEAM B”){
dhxGrid.loadXML(“lib/get_phone.php?location=hk&dept=team b”);
dhxGrid.init();
}else if(tree.getItemText(id) == “TEAM C”){
dhxGrid.loadXML(“lib/get_phone.php?location=hk&dept=team c”);
dhxGrid.init();
}
}

function userManagement(id){
if(tree.getItemText(id) == “User Right Management”){
dhxGrid.loadXML(“lib/get_admin.php”);
dhxGrid.init();
}
}

The init command should be called before the loading data in the grid:

dhxGrid.init(); dhxGrid.loadXML("lib/get_phone.php?location=hk&dept=team c");

Also in case of init from XML file there is no need to call init() at all.