EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: PaulMcGuinness on July 08, 2013, 08:40:15 AM



Title: Tree search and Scroll to
Post by: PaulMcGuinness on July 08, 2013, 08:40:15 AM
Hi All,

I've managed to implement a pretty functional 'search' facility for any easyUI tree, and I can get it to highlight and select the appropriate node.

What I can't do is see to get the jQuery .scrollTo to work with the div, ul or anything within the tree. I should point out that this tree is in a Dialog box (although I can't see that would make any difference)

Any help or suggestions on a viable ".scrollTo' implementation would be greatly appreciated.

Cheers!

Paul

Code:

function amTreeSearch(sInput, sTree)
{
var a=$('#' + sInput).val();
var node = $('#' + sTree).tree('getRoot');
var b=$('#' + sTree).tree('getData',node.target);

var node=search(b,a);
if(node)
{
$('#' + sTree).tree('expandTo', node.target);
$('#' + sTree).tree('select', node.target)
$('#' + sTree).scrollTo(node.target);
//$('#' + sTree).scrollTo(2000);  // This is just to test ... it didn't work either!
}
else
{
showWarning('icon-error','Error','Sorry, I could not find any matches');
}
}

function search(obj, name) {

var a=$('<div>' + obj["text"] + '</div>').text();
var x=a.toLowerCase().indexOf(name.toLowerCase()) != -1

if (x) {
//console.log('****FOUND IT*****');
return obj;
}
if (obj.children || obj._children) {
var ch = obj.children || obj._children;
for (var i = 0; i < ch.length; i++) {
var found = search(ch[i], name);
if (found) {
return found;
}
}
}
return false;
}


Title: Re: Tree search and Scroll to
Post by: stworthy on July 09, 2013, 01:21:54 AM
If you want to scroll the tree, please try the code below:
Code:
var p = $('#' + sTree).parent();  // the parent container
p.scrollTop(200);


Title: Re: Tree search and Scroll to
Post by: PaulMcGuinness on July 09, 2013, 03:02:44 AM
Nope... doesn't work. Is it because it is within a Dialog do you think?