PDA

View Full Version : Determine if node is visible?



dbassett74
5 Jul 2010, 1:25 PM
There doesn't seem to be any built in method of determining if a node is visible. The reason this is handy, is that a node of interest could be many deep, and even though it's parent, may be expanded, this does not mean the node is necessarily visible. So checking if the parentNode of a particular node is expanded does not guarantee that a child node is visible.

Is there any way to do this?

gevik
5 Jul 2010, 1:40 PM
I don't think there is a way to see whether a node is visible but if you have a reference to a given node, then you can call the ensureVisible() method to force that node being visible.

I hope this helps.

dbassett74
5 Jul 2010, 3:29 PM
Unfortunately that won't help me in this situation. I don't want to make it visible, I need to know if it is visible, and if not, do something based on that.

Animal
5 Jul 2010, 9:29 PM
Node? Surely you mean Component?

You mean a Component may be in a card of a card layout which is hidden.

I use this



Ext.override(Ext.Component, {
ensureVisible: function(stopAt) {
var p;
this.ownerCt.bubble(function(c) {
if (p = c.ownerCt) {
if (p instanceof Ext.TabPanel) {
p.setActiveTab(c);
} else if (p.layout.setActiveItem) {
p.layout.setActiveItem(c);
}
}
return (c !== stopAt);
});
this.el.scrollIntoView(this.el.up(':scrollable'));
return this;
}
});


With the pseudo:



Ext.DomQuery.pseudos.scrollable = function(c, t) {
var r = [], ri = -1;
for(var i = 0, ci; ci = c[i]; i++){
var o = ci.style.overflow;
if(o=='auto'||o=='scroll') {
if (ci.scrollHeight < Ext.fly(ci).getHeight(true)) r[++ri] = ci;
}
}
return r;
};

dbassett74
6 Jul 2010, 7:10 AM
I mean node, as in TreeNode.

Animal
6 Jul 2010, 7:24 AM
So if any of its ancestor nodes are collapsed, it's not visible.

Then, if it is in fact present as part of an expanded parent, use Element.getOffsetsTo to find out if it's out of the visible region of the TreePanel's body.

It's all just basic progging.