How do you get / set the scroll position in a table?

I have a table with a fixed header and a scrollable body. I want to know the scroll position in the table so that I can refer to it after the postback and set it where the user was before the postback. I would prefer jQuery to do this, but Javascript is fine too. I'm not sure how much code to send here, because I'm not sure if the problem is that I just don't know the code for this, or the code I have (css) interferes with the solutions I tried.

Any ideas where to start? Is there a way that does this? Ive tried to put this (table style = "overflow: auto; height: 150" onclick = "alert (this.scrollTop)") in the table, but it always returns 0.

Ive also tried other jQuery calls. They all return 0.

+4
source share
2 answers

As far as I know (and I deal with such things every day), native tables cannot handle scrollbars as descriptions. I think that probably your table actually contains a div or other container that actually scrolls the cells of the table. Something like that:

http://jsfiddle.net/mBDjx/46/

I recommend that you check your code using the browser developer tools (usually F12) and check if it is just a table or another element that generates a scroll.

If you understand that it is a div, just check the .scrollTop attribute for the div instead of doing it in a table :-)

Hope it works!

+1
source

This is a scroll and this is what you need to check. this.scrollTop refers to the table, and the top of the table does not change position.

+1
source

Source: https://habr.com/ru/post/1379194/


All Articles