Set selecteditem from an attached URL

Hi,

I am a bit of a newbie so be kind to me. I am using the step-by-step tutorial for creating a file explorer from [url]Start DHTMLX Docs.

I wish to add additional functionality whereby some nodes in the tree link to html pages being displayed in the second column. What i want now is to be able to set selected item from a url in the html pages that get opened up from the tree nodes.

I have tried a link like this

<a href="#" onClick="javascript:window.top.showHTML('/folder/on/my/tree')">Link Name</a>

where showHTML() is defined in the document that contains my tree and i want to set the selected directory to /folder/on/my/tree that i passed in my function but nothing is happening on my tree

below is my showHTML function

		function showHTML(dir){
			alert("show 1:"+dir); //this gets displayed
			var url = "/nprmodel" + dir + "/index.html";
			dir_new = dir.split("/");
			tot = dir_new.length;
			if(tot > 1){
				DPM = dir_new[tot-2];
				SEG = dir_new[tot-1];
				//alert(DPM + " "+ SEG);
				htmlFileName = DPM.replace(".","_")+"_"+SEG+".HTML";
				url = "/nprmodel/MainDataDefs/"+htmlFileName;
			}
			myLayout.cells("b").setText(dir);
			myLayout.cells("b").attachURL(url); //this page getss loaded
			//myTree.selectItem(dir,true); //tried this but it did not work
			var z=dir;  myTree.selectItem(z); myTree.focusItem(z); //this is also not working
		}

Please help.

Hello,

to open and select a certain item you can call openItem and selectItem methods and put an item id as a parameter:

myTree.openItem(itemId);
myTree.selectItem(itemId);

Thank you Alexandra, i tried this and still no luck. To confirm that i have the correct node ids i have this line of code:

myLayout.cells("b").setText(dir); //this correctly sets the heading to the current node id

Trying this doesn’t select the tree node i want to be selected

myTree.openItem(dir);
myTree.selectItem(dir); //dir is the id that the tree uses to id elements uniquely
//myTree.focusItem(dir);

just as i sidenote i have this error in my browser’s javascript error log:

Uncaught TypeError: Cannot call method ‘fromHTML’ of undefined ftypes.js:3
Uncaught TypeError: Cannot set property ‘image’ of undefined

I am using a trial version of the dhtmxtree pro if that helps

Hi Alexandra,

I managed to figure out why this wasn’t working initially. It was because my tree is being loaded partially so sometimes i would try to open and select a node that is not already loaded into memory (i think) so when i first open these nodes and then try this code it works.

Now i am looking for a a way to load the tree’s sub branches after the initial load of the top level nodes (perhaps in the background), I will post back feedback on how far i go with this.

Thank you

Hi Alexandra,

I’ve looked around and i can’t find sample code for this.

I was wondering how i can “dynamically” from script load the path to a given node. i.e. i want to simulate the opening of respective parent(s) node(s) for a given tree node id.

Hi, blestab
Here you can find dynamic opening of node 2-3-1 (step-by-step).
dhtmlx.com/docs/products/dht … tions.html
It achives via method openItemsDynamic()

Thank you so much Darya, that link solved all my problems.

You are welcome!