PDA

View Full Version : Scrolling to a text in the html of a panel



franveragg
19 Aug 2013, 7:49 PM
Hi!
I have a panel with about 2800 characters in the html property where I searchfor a user defined string.
I want to make the panel scroll to the section where the string is found.
I know you can scroll like this:

myPanel.getScrollable().getScroller().scrollTo(0, stringY);

My problem is getting the second parameter, the Y position where the string was found.
I have tried to surround the found string with an HTML element, catching it with Ext.get and document.getElementByID and used all the offsets, top and getY methods of both plain JavaScript and Ext.dom.element to try to get the Y position without any success.
Any ideas?
Thanks in advance!

franveragg
21 Aug 2013, 9:26 AM
anyone?

franveragg
21 Aug 2013, 2:03 PM
Solved it!
I guess I was too tired yesterday because after trying the same thing today it worked!
Solution:
wrap the text with an id: <b id="result">result</b>
scroll to the text like this:
content.getScrollable().getScroller().scrollTo(0,document.getElementById('result').offsetTop,false);

jerome76
22 Aug 2013, 10:04 AM
Nice. You should be also able to use Ext.get('result') instead of document.getElementById('result') :)

franveragg
23 Aug 2013, 7:40 AM
Nice. You should be also able to use Ext.get('result') instead of document.getElementById('result') :)
You are right Jerome! Thanks!
Updated code:

content.getScrollable().getScroller().scrollTo(0, Ext.get('result').offsetTop,false);