How to identify which nodes in TreeView are unfolded

Develop and Deploy Cross-Browser Web Apps .

How to identify which nodes in TreeView are unfolded

Postby joedarock » Fri Feb 12, 2016 12:57 pm

My application has a background process that has to update data inside TreeView nodes that are presently unfolded (expanded). How can I determine which nodes are unfolded?

Joe
joedarock
 
Posts: 161
Joined: Thu Nov 19, 2015 8:39 pm

Re: How to identify which nodes in TreeView are unfolded

Postby support » Mon Feb 15, 2016 2:21 am

"getUIValue" will return those selected ids .
support
 
Posts: 352
Joined: Sat Apr 27, 2013 9:22 am

Re: How to identify which nodes in TreeView are unfolded

Postby joedarock » Thu Feb 18, 2016 12:26 pm

I don't understand how to use this. Can you provide an example to get caption or some other item property of a specified tree node ?
joedarock
 
Posts: 161
Joined: Thu Nov 19, 2015 8:39 pm

Re: How to identify which nodes in TreeView are unfolded

Postby support » Fri Feb 19, 2016 2:11 am

   
Class('App', 'xui.Com',{
Instance:{
iniComponents : function(){
// [[Code created by CrossUI RAD Studio
var host=this, children=[], append=function(child){children.push(child.get(0));};

append(
(new xui.UI.Panel())
.setHost(host,"ctl_panel3")
.setDock("none")
.setLeft(170)
.setTop(20)
.setWidth(420)
.setHeight(230)
.setZIndex(1)
.setCaption("TreeView")
);

host.ctl_panel3.append(
(new xui.UI.TreeView())
.setHost(host,"tv")
.setItems([{
"id" : "node1",
"sub" : ["node11",{
"id" : "node12",
"image" : "http://www.crossui.com/RAD/img/demo.png"
},"node13","node14"],
"caption" : "node1"
},{
"id" : "node2",
"sub" : ["node21","node22","node23","node24"],
"caption" : "node2"
}])
.setSelMode("multibycheckbox")
.setValue("")
);

append(
(new xui.UI.HTMLButton())
.setHost(host,"ctl_htmlbutton904")
.setLeft(170)
.setTop(260)
.setWidth(420)
.setHeight(30)
.setHtml("Get selection nodes")
.onClick("_ctl_htmlbutton904_onclick")
);

return children;
// ]]Code created by CrossUI RAD Studio
},
_ctl_htmlbutton904_onclick:function (profile, e, value){
var ns = this,
selected = ns.tv.getUIValue(true);

alert(selected);

if(selected && selected.length){
var item = ns.tv.getItemByItemId(selected[0]);
alert(item.caption);
}
}
}
});
   
support
 
Posts: 352
Joined: Sat Apr 27, 2013 9:22 am

Re: How to identify which nodes in TreeView are unfolded

Postby joedarock » Fri Feb 19, 2016 1:49 pm

This doesn't work. It gives an error code "Uncaught TypeError: Cannot read property 'getUIValue' of undefined".

Here is how I wrote the code. Except for using button 6 and my instantiation of the 'tv' variable, I think it's exactly what you provided (I'm sure the 'tv' declaration is correct, as it's used in multiple locations in my program):

_ctl_htmlbutton6_onclick:function (profile, e, value){
//var ns = this; //uictrl = profile.boxing();
var tv = xui.UI.TreeView.getFromDom(siteTree); //as in other places in my program
var ns = this,
selected = ns.tv.getUIValue(true);

alert(selected);

if(selected && selected.length){
var item = ns.tv.getItemByItemId(selected[0]);
alert(item.caption);
alert(item.caption);
}

The execution never gets to the first 'alert' call.
joedarock
 
Posts: 161
Joined: Thu Nov 19, 2015 8:39 pm

Re: How to identify which nodes in TreeView are unfolded

Postby support » Sat Feb 20, 2016 4:05 am

You've got the 'tv' object via "getFromDom" already, why used "ns" scope?

Maybe, your code should be

javascript code
_ctl_htmlbutton6_onclick:function (profile, e, value){
var tv = xui.UI.TreeView.getFromDom(siteTree); //as in other places in my program
var selected = tv.getUIValue(true);

alert(selected);

if(selected && selected.length){
var item = tv.getItemByItemId(selected[0]);
alert(item.caption);
alert(item.caption);
}
}
support
 
Posts: 352
Joined: Sat Apr 27, 2013 9:22 am

Re: How to identify which nodes in TreeView are unfolded

Postby joedarock » Mon Feb 22, 2016 2:24 pm

What I originally wanted to do is figure out which nodes are expanded. How can I do that? Is that one of the items in the Items collection? Where can I get documentation on all the available data objects for the TreeView?

BTW, the last example you gave does weird things. The second alert will only display if the first alert is allowed to execute. If you comment out the first alert, the second one doesn't execute, instead giving the error code I referenced in a previous. This might have something to do with other background processes that are constantly updating the tree, since methods like toggleNode don't always execute while my whole program is running, even though the code lines immediately before and after do execute. FYI, my code isn't triggered by a Button-click event as in your example, it's triggered by a TreeView-click event. I do it this way because, when I click on a TreeView node, I need to know which other nodes are also open.
joedarock
 
Posts: 161
Joined: Thu Nov 19, 2015 8:39 pm

Re: How to identify which nodes in TreeView are unfolded

Postby support » Tue Feb 23, 2016 2:19 am

You can use "_checked" to determine it:

if(item._checked){
// expand
}else{
// fold
}
support
 
Posts: 352
Joined: Sat Apr 27, 2013 9:22 am

Re: How to identify which nodes in TreeView are unfolded

Postby joedarock » Fri Feb 26, 2016 1:43 pm

This still doesn't work because 'selected' (previous example) is returning a null value in the alert.
joedarock
 
Posts: 161
Joined: Thu Nov 19, 2015 8:39 pm

Re: How to identify which nodes in TreeView are unfolded

Postby support » Sat Feb 27, 2016 7:11 am

Please use mouse CLICK to select some Items first.
support
 
Posts: 352
Joined: Sat Apr 27, 2013 9:22 am


Return to CrossUI for Web Apps

Who is online

Users browsing this forum: No registered users and 1 guest

cron