Best way to get currently scrolled to position
Best way to get currently scrolled to position
Im trying to find the best way to get the exact position that the viewer has scrolled to, using the scroller extension.
Heres a JSBin of what I've tried thus far.
I tried to use the last rowIndex that was created by createdRow
, but that obviously gets the very bottom row, not the very top row.
I thought that maybe one idea that would be possible, is get the last rowIndex of the last created row, then subtract however many rows makes the height of the table. But that doesn't seem to work at all... And even if it did, if they do something like use the code in the vertical page fitting blog (which is really cool btw), then that would obviously throw off the math. And it would obviously be susceptible to some complications if the scroller.boundaryScale
or scroller.displayBuffer
were utilized
I figure theres gotta be a better way to do that anyways. I didn't see any events related to the scroller extension (which is really weird by the way... I would think this would be an event), or anything in the API to get the current index that was scrolled to.
I thought this would be a relatively simple task, lol
Thanks!
Answers
I found some DataTables settings that should be relevant
oScroller.s.baseRowTop
oScroller.s.topRowFloat
However they both have the same value... what would be the best one to go with?
And is there anything I can attach to to see if they have been changed? Short of just looping something to see if the value is any different.
Oh, I guess the
draw
works...So I guess all thats left is... whats the difference between
topRowFloat
andbaseRowTop
? :)As in the pixel position?
$().scrollTop()
on the controlling container is probably best.Allan
I just mean the position that can be used with
row().scrollTo()
Im using it for the keepConditions plugin, including the scroller position as one of the conditions. So I just need to find the best way to get the current and accurate "position" that can be used with
row().scrollTo()
Yeah I think I got it.
To get the current position, in the
draw
, I logto the hash, then when the page loads, in the
init
, I grab the value, and basically:Seems to work fine.
@allan - You think updating the hash via the
draw
might cause a little too much overhead? I can't think of a better way to do it. It needs to be the latest current row.