EasyUI Forum
May 15, 2024, 04:34:52 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Using .scroll, .scrollTop or .animate in a Dialog on a Tree (li/ul list)  (Read 9873 times)
PaulMcGuinness
Newbie
*
Posts: 15


View Profile Email
« on: July 15, 2013, 05:57:18 AM »

Hi,

I'm using a Dialog to show a 'tree', I've implemented a search function that finds and highlights the node, but I cannot work out how to ensure that it is visible (e.g. 'Scroll to') within a dialog.

I suspect this may be due to the fact that the tree is essentially li/ul combinations which don't expose an 'offset' or 'offsetTop' property within the DOM.

The search is achieved like so:

                  $('#myTree').tree('expandTo', node.target);
                  $('#myTree').tree('select', node.target)

And of course at this moment, the selected item is showing the 'tree-node-selected' class, so can be referenced via $('.tree-node-selected'), or more specifically; $('.tree-node-selected')[1] as there seems to be a ghost set of the same li/ui's created by the tree function of easyUI.

I've spent two whole days looking at this now, and am getting nowhere.

Any suggestions welcome at this point...

Cheers,

Paul

Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 15, 2013, 07:54:41 PM »

Try to extend a new method 'scrollTo'.
Code:
$.extend($.fn.tree.methods,{
scrollTo: function(jq, nodeEl){
return jq.each(function(){
var t = $(this);
var n = $(nodeEl);
var c = t.parents('div:first');
var ntop = n.offset().top;
var ctop = c.offset().top;
if (ntop < ctop){
c.scrollTop(c.scrollTop() + ntop - ctop);
} else if (ntop + n.outerHeight() > ctop + c.height() - 18){
c.scrollTop(c.scrollTop() + ntop + n.outerHeight() - ctop - c.height() + 18);
}
});
}
});

Call 'scrollTo' method to make the target node inside the current viewport.
Code:
$('#myTree').tree('scrollTo', node.target);
« Last Edit: July 15, 2013, 07:57:26 PM by stworthy » Logged
PaulMcGuinness
Newbie
*
Posts: 15


View Profile Email
« Reply #2 on: July 16, 2013, 12:45:18 AM »

Thanks for the prompt reply.

Is this going to work within a .dialog? Only I'm not getting much joy even when implementing the code directly rather than extending Sad

Regards,

Paul
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!