1

I would like like to get the scroll position of a tbody in a lightning component, what's the supported way to do this?

cmp.find('myComponent').getElement().scrollTop is undefined. If I do this in pure javascript it works fine, but there's something funny going on in lightning. I thought reading the dom was acceptable. Thanks for any insights into this.

  <table>

<tbody style="height:100px; display:block; overflow:auto;" onscroll="console.log(this.scrollTop);">
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>
  <tr><td>1</td></tr>             
</tbody>

5

What component has aura:id="myComponent" on it? I would expect to see something like:

<tbody aura:id="myComponent" ...

in your Lightning markup.

Also, I just checked and scrollTop is not currently exposed on SecureElement (the virtual DOM element class your code sees when running inside of Locker Service).

Please open a support case on this part of your question and let our support team know I have already created bug W-3189035 to track this.

BTW you can use element.getAttribute("scrollTop") as an alternate syntax until we get the getter/setter shorthand version exposed.

7
  • Sorry I didn't post the full mark up. You're right the lightning component markup has aura:id="myComponent". I was testing outside of lightning to see if the issue was a general HTML nuance with tbody vs a lightning thing. I thought it might be something like this. This is probably a stupid question but where is the best place to find out what is and isn't supported in the lightning virtual dom, as well as what methods are available? – Scott Morrison Jun 10 '16 at 17:48
  • case # 13992694 – Scott Morrison Jun 10 '16 at 18:21
  • cmp.find('myComponent').getElement().getAttribute("scrollTop") returns null, that probably makes sense if it's not a secure property that can be accessed yet? – Scott Morrison Jun 10 '16 at 18:25
  • No - something else is going on here - there is no per attribute filtering via SecureElement.getAttribute(). The DOM spec states: getAttribute() returns the value of a specified attribute on the element. If the given attribute does not exist, the value returned will either be null or "" (the empty string) – Doug Chasman Jun 10 '16 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.